(1)this(参数):调用本类中另一种形成的构造函数(应该为构造函数中的第一条语句)
class Point
{
private int x,y;
public Point(int x,int y)
{
this.x=x; //this它代表当前对象名
this.y=y;
}
public Point()
{
this(0,0); //this(参数)调用本类中另一种形成的构造函数
}
}
(2)如果函数的形参与类中的成员数据同名,这时需用this来指明成员变量名
class Point
{
private int x,y;
public Point(int x,int y)
{
this.x=x; //this它代表当前对象名
this.y=y;
}
}
(3)如果函数的局部变量与成员变量相同时,成员变量会被隐藏。此时如果要用到成员变量的话,就需this。
class Point
{
private int x = 3;
public Point()
{
int x;
x = 5;
system.out.println(x); //输出5
system.out.println(this.x); //输出3
}
}
http://blog.youkuaiyun.com/zhandoushi1982/article/details/5445314