/**
-
@program: jvm
-
@ClassName Test1
-
@Description:通过子类引用父类的静态字段,不会导致子类初始化
-
@author: 牧小农
-
@create: 2021-02-27 11:42
-
@Version 1.0
**/
public class Test1 {static {
System.out.println(“Init Superclass!!!”);
}public static void main(String[] args) {
int x = Son.count;
}
}
class Father extends Test1{
static int count = 1;
static {
System.out.println(“Init father!!!”);
}
}
class Son extends Father{
static {
System.out.println(“Init son!!!”);
}http://www.yezidianjing.com/
}