标签:stat ext 执行 代码 类构造 构造 str color string
public class HelloA { static { System.out.println("static A"); } { System.out.println("I‘m A class"); } public HelloA() { System.out.println("HelloA"); } } class HelloB extends HelloA { static { System.out.println("static B"); } { System.out.println("I‘m B class"); } public HelloB() { System.out.println("HelloB"); } public static void main(String[] args) { new HelloB(); } }
//打印结果:
  static A
  static B
  I‘m A class
  HelloA
  I‘m B class
  HelloB
 
总结:执行顺序为:
父类静态代码块
子类静态代码块
父类普通方法
父类构造方法
子类普通方法
子类构造方法
标签:stat ext 执行 代码 类构造 构造 str color string
原文地址:https://www.cnblogs.com/shuaiding/p/11040630.html