java几个经典传参,你懂了吗

例题1

    public static void main(String[] args)
    {
        int x = 4;
        show(x);
        System.out.println(x);
    }
    public static void show(int x) {
        x = 2;
    }

java几个经典传参,你懂了吗_第1张图片

例题2

public class DD {
    int x = 3;
    public static void main(String[] args)
    {
        Demo d = new Demo();
        d.x = 10;
        show(d);//show(new Demo());
        System.out.println(d.x);
    }
    public static void show(Demo d)
    {
        d.x = 6;
    }

}

例题3

public static void main(String[] args)
{
    int[] arr = new int[2];
    show(arr);
    System.out.println(arr[0]);
}
    public static void show(int[] arr)
    {
        arr[0]++;
    }

你可能感兴趣的:(JAVA基础)