代码分析系列 内存执行过程

1、内存执行过程:(六:01:32:08-->)

package primary;

public class Main {
    public static void main(String args[]){
        Main m= new Main();
        int day = 15;
        Birthday b1 = new Birthday(27,11,1988);
        Birthday b2 = new Birthday(23,04,2013);
        m.change1(day);
        m.change2(b1);
        m.change3(b2);    
        b1.Display();
        b2.Display();
        }
    void change1(int num){
        num = 123;
    }
    void change2(Birthday b){
        b = new Birthday(04,01,1989);
    }
    void change3(Birthday b){
        b.setDay(26);b.setMonth(01);b.setYear(2015);
        
    }
}

class Birthday{
    int day;int month;int year;
    Birthday(int _day, int _month, int _year){
        day = _day;month = _month;year = _year;
    }
    void Display(){
        System.out.println("Birthday is:"+year+"-"+month+"-"+day);
    }
    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;
    }
    
}

输出:

Birthday is:1988-11-27
Birthday is:2015-1-26

2、涉及知识:

  栈内存和堆内存;引用传递和值传递;栈变量用完就释放,堆内存若干时间后会被GC回收。

  

转载于:https://www.cnblogs.com/RunForLove/p/4337388.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值