您可以使用此关键字来–
如果实例变量与局部变量在构造函数或方法中具有相同的名称,则将它们区分。
class Student {
int age;
Student(int age) {
this.age = age;
}
}在类中从其他类型调用一种类型的构造函数(参数化的构造函数或默认类型)。这称为显式构造函数调用。
class Student {
int age
Student() {
this(20);
}
Student(int age) {
this.age = age;
}
}