Package com.day11. parameter passing;
public class Demo {
/**
* @param args
* Basic Data type parameter value is passed without changing the original value, because the stack is played after the call, and the local variable disappears
* The value of the reference data type is passed, changing the original value, because even if the method is bouncing but the array object of the heap memory is still there, you can continue to access the
* Both are value passing, one passing is the specific value, one is passing the address value
*/
public static void Main (string[] args) {
int a=1;
int b=2;
Change (A, b);
System.out.println ("a=" +a+ "" + "b=" +b);//a=1 b=2
Int[] arr={1,2};
Changearray (arr);
System.out.println ("arr[0]=" +arr[0]+ "" + "arr[1]=" +arr[1]);//arr[0]=2 arr[1]=1
}
private static void Change (int a, int b) {
int temp;
Temp=a;
A=b;
B=temp;
System.out.println ("a=" +a+ "" + "b=" +b);//a=2 b=1
}
private static void Changearray (int[] arr) {
int temp;
TEMP=ARR[0];
ARR[0]=ARR[1];
Arr[1]=temp;
System.out.println ("arr[0]=" +arr[0]+ "" + "arr[1]=" +arr[1]);//arr[0]=2 arr[1]=1
}
}
java-parameter passing