在无参的构造方法中可以使用this关键字调用有参数的构造方法,this必须放在无参构造方法中的第一句。
public class Demo1 { public Demo1() { this("this调用有参构造方法"); System.out.println("无参构造方法"); } public Demo1(String name){ System.out.println("有参构造方法"); } }