1 package test; 2 3 public class TestB { 4 5 public TestB() { 6 System.out.println("TestB的无参构造函数..."); 7 } 8 9 }
1 package test; 2 3 public class TestA extends TestB { 4 5 public TestA(int i) { 6 System.out.println(i); 7 } 8 9 public static void main(String[] args) { 10 TestA a = new TestA(1); 11 } 12 13 }
执行上述代码后,运行结果如下:
从上述结果得知,在TestA的无参构造函数中默认调用了父类TestB的无参构造函数,即默认执行了super()代码
时间: 2024-12-28 17:09:11