1 package test_1_1; 2 3 public class A { 4 5 /** 6 * 初始化基类,构造器调动顺序 7 */ 8 9 public A(int i){ 10 System.out.println("this is A"); 11 } 12 }
1 package test_1_1; 2 3 public class B { 4 5 public B(int i){ 6 System.out.println("this is B"); 7 } 8 }
1 package test_1_1; 2 3 public class C extends A{ 4 5 public C() { 6 super(1); 7 B b = new B(1); 8 System.out.println("this is C"); 9 } 10 11 }
1 package test_1_1; 2 3 public class Test { 4 5 public static void main(String[] args) { 6 7 C c = new C(); 8 9 } 10 11 }
结果如下:
this is A
this is B
this is C
[20-05-04][Thinking in Java 1]Java Inheritance 1 - Inheritance Syntax 2
原文:https://www.cnblogs.com/mirai3usi9/p/12825870.html