public class MyTest1{
public static void main(String[] args) {
System.out.println(MyChild1.str);
System.out.println(MyChild1.str2);
}
}
class MyParent1{
public static String str = "hello myParent1";
//静态块,初始化的时候被调用
static {
System.out.println("myParent1 static block");
}
}
class MyChild1 extends MyParent1{
public static String str2 = "hello MyChild1";
static {
System.out.println("MyChild1 static block");
}
}
原文:https://www.cnblogs.com/boychen/p/11674729.html