this 关键字
-
this 可以用来修饰: ***属性,方法构造器.
-
this 修饰属性和方法时, this理解为:当前对象
在类的方法中我们可以使用this.属性和this.方法
-
构造器和上面类似,是构造器形参与属性同名时使用.
-
一句话总结 : 原来怎么写就怎么写,一旦重名就加上this!
***
public boy(String name, int age) {
this.name = name;
this.age = age;
}
232 . this调用构造器
-
在类的构造器中,可以使用this(形参列表)的方式调用本类中其他构造器.
-
只能调别的,不能自己调自己.
-
如果一个类中有几个构造器,则最多有 n-1个构造器使用this(形参列表)调用.
-
规定 : this(形参列表)必须声明在当前构造器 首行.
-
构造器内部,最多只能声明 一个 this.(形参列表)来调用其他构造器.
-