1 public class Par {
 2 
 3     public Par() {
 4         System.out.println("父类--constructor");
 5     }
 6 
 7     static {
 8         System.out.println("父类--statc");
 9     }
10 
11     {
12         System.out.println("父类普通代码块");
13     }
14 }
15 
16 public class Sub extends Par {
17 
18     public Sub() {
19         super();
20         System.out.println("子类--constructor");
21     }
22 
23     static {
24         System.out.println("子类--static");
25     }
26 
27     {
28         System.out.println("子类--普通代码");
29     }
30 
31     public static void main(String[] args) {
32         Sub sub = new Sub();
33     }
34 }

执行顺序:

父类----static

子类---static

父类普通代码块

父类----constructor

子类---普通代码块

子类------constructo

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-04-07
  • 2021-07-15
猜你喜欢
  • 2022-12-23
  • 2022-02-22
  • 2021-06-11
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案