构造方法关键字---this

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());

    }

}

 

猜你喜欢

转载自www.cnblogs.com/qurui1998/p/10548573.html
0条评论
添加一条新回复