this调用有参构造方法

在无参的构造方法中可以使用this关键字调用有参数的构造方法,this必须放在无参构造方法中的第一句。

public class Demo1 {
    public Demo1() {
        this("this调用有参构造方法");
        System.out.println("无参构造方法");
    }
    public Demo1(String name){
        System.out.println("有参构造方法");
    }
}

 

posted @ 2018-06-24 15:43  xiaotao520  阅读(380)  评论(0编辑  收藏  举报