java 内存分析之堆栈空间

本文通过一个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

内存分析图:

 

转载于:https://www.cnblogs.com/Mike_Chang/p/6947227.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值