构造方法关键字---this

时间:2022-05-22 23:23:16

this 可以在构造方法之间进行调用
*this在构造方法之间调用 this()

 this 可以在构造方法之间进行调用
*this在构造方法之间调用 this() package cn.homework.demo4; public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public Person() {
this("李登",22);
} } package cn.homework.demo4; public class TextPerson { public static void main(String[] args) {
Person p=new Person();
System.out.println(p.getName()+" "+p.getAge()); } }