package com.fea.test.init; public class Father { static{ System.out.println("Father_静态初始化块"); } public static String static_str="Father_静态字段"; { System.out.println("Father_初始化块"); } public String str="Father_字段"; public Father(){ System.out.println("Father_构造函数Father()"); } public Father(String str){ System.out.println("Father_构造函数Father(String str)"); } } ****************************************************************************** package com.fea.test.init; public class Child extends Father { static{ System.out.println("Child_静态初始化块"); } public static String static_str="Child_静态字段"; { System.out.println("Child_初始化块"); } public String str="Child_字段"; public Child(){ System.out.println("Child_构造函数Child()"); } public Child(String str){ System.out.println("Child_构造函数Child(String str)"); } public static void main(String[] args) { new Child(); /** * * *************************** * * * * *1.父类的静态变量或者静态块 * * *2.父类的静态变量或者静态块 * * *3.父类的静态变量或者静态块 * * *.......... * * **********|**************** * | * *************************** * * * * *4.子类的静态变量或者静态块 * * *5.子类的静态变量或者静态块 * * *6.子类的静态变量或者静态块 * * *.......... * * **********|**************** * | * *************************** * * * * *7.Object的初始化, * * *8.父类的非静态变量或者代码块 * * *9.父类的非静态变量或者静态块 * * *10.父类的非静态变量或者静态块 * * *.......... * * *11父类的构造函数(在子类构造 * * *函数中调用的父类构造函数, * * *默认为无参构造函数) * * **********|**************** * | * *************************** * * * * *12.子类的非静态变量或者代码块 * * *12.子类的非静态变量或者静态块 * * *13.子类的非静态变量或者静态块 * * *.......... * * *14子类的构造函数 * * ************************** * * * * * * * *继承体系的类加载,先加载父类的静态变量或者静态块,然后加载子类的静态变量或者静态块, *在父类或者子类中,会按照静态变量或者静态块在类中的先后顺序而先后加载 *静态变量或者静态块初始化以后,会初始化父类的非静态变量或者非静态代码块(顺序和它们 *在类中的出现的先后顺序一样)初始化父类的构造函数,然后是子类的. * * */ } }