this,当成员变量和局部变量名字重名时,可以用关键字来区分。
this 代表当前对象,就是所在函数所属的对象的引用。
即哪个调用了this所在的函数,this就代表哪个函数。
应用:1,构造方法间的调用
注意,只能定义在构造方法的第一行,因为对象要先初始化,才能执行。
private String account;。
private int password;。
public String name;
public double balance;
void setAccount(String acount){
this.account=acount;
}
String getAccount(){
return account;
}
void setPassword(int password){
this.password=password;
}
int getPassword(){
return password;
}