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() { 6 System.out.println("TestA的無參構造函數..."); 7 } 8 9 public TestA(int i) { 10 System.out.println("TestA的有參構造函數..."); 11 } 12 13 public static void main(String[] args) { 14 TestA a1 = new TestA(); 15 TestA a2 = new TestA(1); 16 } 17 18 }
執行上述代碼后,運行結果如下:

從上述結果得知,在TestA的有參/無參構造函數中均默認調用了父類TestB的無參構造函數,即默認執行了super()代碼
