this问题
程序中 MyDate new_date = new MyDate(this);中的this 在本程序中起到什么作用?麻烦解释一下??(有些说是把本身当做参数赋给其他对象,本身是指哪个??)public class MyDate
{
public static void main(String[] args)
{
MyDate my_birth=new MyDate(22,7,1964);
MyDate the_next_week=my_birth.addDays(7);
the_next_week.print();
}
public MyDate(int day,int month,int year)
{
this.day = day;
this.month = month;
this.year = year;
}
public MyDate(MyDate date) {
this.day = date.day;
this.month = date.month;
this.year = date.year;
}
public int getDay() {
return day;
}
public void setDay(int day)
{
this.day = day;
}
public MyDate addDays(int more_days)
{
MyDate new_date = new MyDate(this); //这里的this 是什么意思??
new_date.day = new_date.day + more_days;
return new_date;
}
public void print()
{
System.out.println("MyDate: " + day + "-" + month + "-" + year);
}
private int day; //日
private int month; //月
private int year; //年
}