首页 > 代码库 > java 内存分析

java 内存分析

技术分享
package Demo;

public class Demo {
    public static void main(String[] args) {
        Demo demo = new Demo();  
        int date = 9;
        BirthDate d1 = new BirthDate(7, 7, 1970);
        BirthDate d2 = new BirthDate(5, 8, 2000);
        demo.change1(date);
        demo.change2(d1);
        demo.change3(d2);

    }
    public void change1(int i) {
        i = 1234;
    }
    public void change2(BirthDate b) {
        b = new BirthDate(22, 2, 2004);
    }
    public void change3(BirthDate b) {
        b.setDay(22);
    }
}
测试类
技术分享
package Demo;

public class BirthDate {
    private int day;
    private int month;
    private int year;
    
    public BirthDate(int d, int m, int y) {
        day = d;
        month = m;
        year = y;
    }
    public void Display() {
        System.out.println(day+"-"+month+"-"+year );
    }
    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }
    
}
java bean

内存分析图:

技术分享

 

java 内存分析