public class A { String name; int age; public A() { this("Jack",23); } public A(String name,int age) { this.name =name; this.age=age; }public static void main(String args[]) { A test=new A(); System.out.println("name is "+test.name+"I am "+test.age; } }
在构造函数中,如果不在第一行指定构造器之间的调用关系,即使用this(),那么编译器会给你加上super()
那么就会发生super()->this()->super()的执行过程
为了避免多次创建对象,this()和super()的调用必须在第一行