子父类间 静态代码块,代码块,构造函数的运行顺序
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