this修饰的变量用于指代成员变量
解决局部变量隐藏成员变量
package new1;
public class Student {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age ) {
this.age = age;
}
public int getAge() {
return age;
}
public void show() {
System.out.println(name + "," + age );
}
}
package new1;
public class StudentDemo {
public static void main(String[] args) {
Student s = new Student();
s.setName("张三");
s.setAge(30);
s.show();
}
}