this表示当前对象的引用
用在方法里
代表调用该方法的当前对象
用在构造方法里
该构造器所创建的新对象
1.2 用法
在类本身的方法或构造器中引用该类的实例变量和方法
将当前对象作为参数传递给其它方法或构造器
用来调用其他的重载的构造器
1.3 实例
public class Test7
{
public static void main(String[] args)
{
Date d = new Date(2013,11,3);
d.display();
Date d1 = d.getInstance();
d1.display();
}
}
class Date
{
int year;
int month;
int day;
public Date()
{
this.year = 2008;
this.month = 8;
this.day = 8;
}
public Date(int year,int month,int day)
{
this();
this.year = year;
this.month = month;
this.day = day;
}
public Date getInstance()
{
this.year = 2014;
this.month = 1;
this.day = 1;
return this;
}
void display()
{
String msg = this.year+"/"+this.month+"/"+this.day;
System.out.println(msg);
}
}
该博客教程视频地址:http://geek99.com/node/1609