JAVA this,
分享于 点击 1346 次 点评:93
JAVA this,
//this(当前对象)(对象.后面(属性和方法))
//指向当前对象,
//例如:
public String teacherName;
public int teacherAge;
public Teacher(String teacherName,int teacherAge){
//前面的属性名 = 参数名
//以此来辨别 属性名和参数名
//当前局部变量名称和全局变量冲突的情况下(以局部变量为主(全局变量被覆盖))
this.teacherName = teacherName;
this.teacherAge = teacherAge;
}
//也可以用this.方法名(),以此来调用
//构造方法不可被调用,但是可以被同类的构造方法调用
//this(参数1,参数2,参数3) 此句话必须是当前构造方法的第一行,不可有第二行调用类似的方法
this.属性
this.方法名()
this();
相关文章
- 暂无相关文章
用户点评