Java——面向对象 this关键字

this,当成员变量和局部变量名字重名时,可以用关键字来区分。

this 代表当前对象,就是所在函数所属的对象的引用。

即哪个调用了this所在的函数,this就代表哪个函数。

应用:1,构造方法间的调用

注意,只能定义在构造方法的第一行,因为对象要先初始化,才能执行。

 1     private String account;。
 2     private int password;。
 3     public String name;
 4     public double balance;
 5     void setAccount(String acount){
 6         this.account=acount;
 7     }
 8     String getAccount(){
 9         return account;
10     }
11     void setPassword(int password){
12         this.password=password;
13     }
14     int getPassword(){
15         return password;
16     }
原文地址:https://www.cnblogs.com/freemrz/p/3665076.html