Java关键字-this
关键字:this
* 1.this可以用来修饰,属性、方法、构造器
* 2、this修饰属性和方法
* this理解为,当前对象
* 3.this调用构造器
* this必须声明在构造器首行
public class ThisTest { } class Person6{ private int age; private String name; public Person6() { } public Person6(int age) { this.age = age; } public Person6(int age,String name) { //this调用构造器 this(age); this.name=name; } // public Person6(int age, String name) { // //this关键字 // this.age = age; // this.name = name; // } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } }