码:
class A {
static {
System.out.println("loading A static 1");
}
static {
System.out.println("loading A static 2 B.c= "+B.c);
}
static {
System.out.println("loading static 3");
}
static int a=10;
A(){
}
}
class B extends A{
static {
System.out.println("loading B A.a= "+A.a);
}
static int c = 50;
}
public class Test {
public static void main(String[] args) {
new B();
}
}
输出:
loading A static 1
loading A static 2 B.c= 0
loading static 3
loading B A.a= 10
从这个出来可以说,父类在子类之后加载,但子类在父类之后初始化?
如果是这样,JVM如何加载类层次结构?