day05-基本类型与引用类型作为方法参数的区别_debug说明
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.inmind.array01;
|
||||||
|
/*
|
||||||
|
基本类型与引用类型作为方法参数的区别_debug说明
|
||||||
|
基本数据类型:保存具体的值,值传递
|
||||||
|
引用数据类型:保存地址值,址传递
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class Demo08 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 10;
|
||||||
|
int b = 20;
|
||||||
|
changValue(a,b);
|
||||||
|
System.out.println(a);//10
|
||||||
|
System.out.println(b);//20
|
||||||
|
}
|
||||||
|
|
||||||
|
//基本数据类型作为参数,保存具体的值,值传递
|
||||||
|
public static void changValue(int a,int b) {
|
||||||
|
a = a+a;
|
||||||
|
b = b+b;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.inmind.array01;
|
||||||
|
|
||||||
|
public class Demo09 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] arr = {10, 20};
|
||||||
|
changValue(arr);
|
||||||
|
System.out.println(arr[0]);//20
|
||||||
|
System.out.println(arr[1]);//40
|
||||||
|
}
|
||||||
|
|
||||||
|
//引用数据类型作为参数,保存具体的地址,址传递
|
||||||
|
public static void changValue(int[] arr) {
|
||||||
|
arr[0] = arr[0] + arr[0];
|
||||||
|
arr[1] = arr[1] + arr[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user