static块的执行顺序问题

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Test {
public static void main(String[] args) {
B b=new B();
}
static{
System.out.println("Test static块执行");
}
public Test(){
System.out.println("Test类初始化。。。。。");
}
static class A{
static{
System.out.println("A的static块执行");
}
public A(){
System.out.println("A类初始化。。。。。");
}
}
static class B extends A{
static {
System.out.println("B的static初始化");
}
public B(){
System.out.println("B类初始化。。。。。");
}
}
}

输出如下

Donate comment here