目录
值传递
package com.zhang.parameter;
public class MethodDemo1 {public static void main(String[] args) {int a = 10;System.out.println(a);System.out.println("~~~~~~~~~~~~~~~");change(a);System.out.println(a);}public static int change(int num){System.out.println(num);num = 330;System.out.println(num);return num;}
}
地址传递
package com.zhang.parameter;
public class MethodDemo2 {public static void main(String[] args) {int[] arr = {10,20,30,40,50};System.out.println(arr[0]);System.out.println("~~~~~~~~~~~~~~~~");change(arr);}public static void change(int[] arr){System.out.println(arr[0]);arr[0] = 30;System.out.println(arr[0]);}
}