版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guchunchao/article/details/82807036
class A {
static {
System.out.println("A static block");
}
{
System.out.println("A block");
}
public A() {
System.out.println("A Constructor");
}
}
class B extends A{
static {
System.out.println("B static block");
}
{
System.out.println("B block");
}
public B() {
System.out.println("B Constructor");
}
}
public class Test {
public static void main(String[] args) {
A b = new B();
//B b = new B(); //结果相同
}
}
---------------------------------------------------------------
执行结果:
A static block
B static block
A block
A Constructor
B block
B Constructor