代码测试示例:
package com.st;
public class StaticTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
A b = new B();
}
}
class A{
static{
System.out.println("A static");
}
{
System.out.println("A normal");
}
public A(){
System.out.println("A con");
}
}
class B extends A{
static{
System.out.println("B static");
}
{
System.out.println("B normal");
}
public B(){
super();
System.out.println("B con");
}
}
运行结果:
A static
B static
A normal
A con
B normal
B con
结论:按以下顺序初始化
父类static模块
子类static模块
父类普通模块
父类构造方法
子类普通模块
子类构造方法