public class EveryDay {
public EveryDay() {
System.out.println("ClassA");
}
static {
System.out.println("static A");
}
{
System.out.println("I'm A class");
}
}
public class WeekTemplate extends EveryDay{
public WeekTemplate(){
System.out.println("ClassB");
}
static {
System.out.println("static B");
}
{
System.out.println("I'm B class");
}
public static void main(String[] args) {
new WeekTemplate();
}
}
打印结果:
static A
static B
I'm A class
ClassA
I'm B class
ClassB
以上栗子说明了Java类的加载顺序问题。