在局部变量屏蔽成员变量的情况下,如果想要绕开这种屏蔽,能访问到成员变量,需要使用this关键字。
class Student{
//成员变量
private String stuId;
private String stuName;
private int stuAge;
//构造器(构造方法)
Student(){
System.out.println("无参构造器");
}
Student(String stuId){
this.stuId = stuId;
System.out.println("1个参数构造器");
}
Student(String stuId, String stuName){
this.stuId = stuId;
this.stuName = stuName;
System.out.println("2个参数构造器");
}
Student(String stuId, String stuName, int stuAge){
this.stuId = stuId;
this.stuName = stuName;
this.stuAge = stuAge;
System.out.println("3个参数构造器");
}
}