class HelloA { public HelloA() { System.out.println("HelloA"); } { System.out.println("I'm A class"); } static { System.out.println("static A"); } } class HelloB extends HelloA { public HelloB() { System.out.println("HelloB"); } { System.out.println("I'm B class"); } static { System.out.println("static B"); } } public class Demo { public static void main(String[] args) { System.out.println("main start"); new HelloB(); new HelloB(); System.out.println("main end"); } }
结果
main start static A static B I'm A class HelloA I'm B class HelloB I'm A class HelloA I'm B class HelloB main end