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回收。