java内存图

时间:2024-11-08 08:17:08
package com.qcby.Test;

public class Test {
    public static void main(String[] args) {
        int[][] arr1 = {
                {1,2},
                {2,2},
                {3},
                {1,1,4}
        };
        int[][] arr2 = new int[3][2];
        arr2[1] = new int[] {3,4,5,6};
        
        String[][] arr3 = {
                {"aa","vv"},
                {"cc","ww","ff"},
                {new String("xxx")},
        };
        int[][][] arr5 = {
                { {1}, {2,2} },
                { {3,4} , {1} }
        };
    }
    
}

package com.qcby.Test;

public class Test {
    public static void main(String[] args) {
        int[] arr1 = {1,2,3,4};
        arr1 = new int[] {2,3,3,1,3};
        //基本类型:byte,short,int,long,float,double,char,boolean
        int[] arr2 = arr1;
        
        String[] arr3 = {"aa","cc",new String("mmm"),"aaa"};
        
        Person aa = new Person();
        
        Person[] arr4 = {new Person(),new Person(),aa};
    }
    
}

引用传递传的是据点的地址

package com.qcby.Test;

public class Test {
    public static void main(String[] args) {
        Person x1 = new Person();
        Person x2 = new Person();
        x1.age = 10;
        x2.age = 20;
        m1(x1,x2);
    }
    public static void m1(Person a,Person b) {
        Person w1 = a;
        a = b;
        b = w1;
    }

}

package com.qcby.Test;

public class Test {
    public static void main(String[] args) {
        Person x1 = new Person();
        Person x2 = new Person();
        x1.age = 10;
        x2.age = 20;
        m1(x1,x2);
    }
    public static void m1(Person a,Person b) {
        Person w1 = a;
        a = b;
        b = w1;
    }

}