- 类的加载链接和初始化
验证问题:①对于静态字段来说,只有直接定义了该字段的类才会被初始化;
②当一个类在初始化时,要求其父类都已经初始化完毕了
验证代码:
public class MyTest1 { public static void main(String[] args) { System.out.println(MyChild1.str2); } } class MyParent1{ public static String str= "hello world"; static { System.out.println("Myparent1 static block"); } } class MyChild1 extends MyParent1{ public static String str2 = "welcome"; static { System.out.println("MyChild1 static block"); } }