为何父类的构造代码块会在子类的静态代码块之后执行?
- public class Father {
- {
- System.out.println("father constructer block");
- }
- static{
- System.out.println("father static block");
- }
复制代码- public class Child extends Father {
- {
- System.out.println("children constructer block");
- }
- static{
- System.out.println("children static block");
- }
复制代码- public class Init {
- public static void main(String[] args) {
- Father f_ = new Child();
- }
-
- }
复制代码
执行结果:
- father static block
- children static block
- father constructer block
- children constructer block
复制代码
|
|