典型案例, 建议自己调试代码,观看结果,分析流程!
public class TestYourCRoot { public static void main(String[] args) { // TODO Auto-generated method stub new c3(); } } class c1{ static { System.out.println("c1 static 1"); } { System.out.println("c1 codedata 4"); } public c1(){ System.out.println("c1 构造器 5"); } } class c2 extends c1{ static { System.out.println("c2 static 2"); } { System.out.println("c2 codedata 6"); } public c2() { System.out.println("c2 构造器 7 "); } public c2(String msg) { //super(); this(); System.out.println("c2 带参数的构造器 8 " + msg); } } class c3 extends c2{ static{ System.out.println("c3 static 3"); } { System.out.println("c3 codedata 9"); } public c3() { super("雇佣兵"); System.out.println("c3 构造器 10"); } }
0则评论给“理解 静态代码块, 非静态代码块 构造方法 的执行过程”