子类继承父类,方法的执行顺序

匿名 (未验证) 提交于 2019-12-02 21:45:52
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

 

总结:执行顺序为:

  父类静态代码块

  子类静态代码块

  父类普通方法

  父类构造方法

  子类普通方法

  子类构造方法

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!