public class A {
static{
System.out.println("A static");
}
{
System.out.println("A");
}
public A(){
System.out.println("A的构造");
}
}
public class B extends A {
static{
System.out.println("b static");
}
{
System.out.println("B");
}
public B(){
System.out.println("B的构造");
}
public static void main(String args[]){
System.out.println("m***");
A a= new B();
System.out.println("n****");
}
}
输出结果:
A static
b static
m***
A
A的构造
B
B的构造
A
A的构造
n****
先基类的static ->子类的static ->基类的{}->子类的{}->基类的构造->子类的构造