Java创建子类——初始化顺序

2017-09-09  本文已影响18人  远o_O

1、前记

2、顺序

father static!!!
child static!!!
father NaN Static
father Constructor
child NaN Static
child Constructor

3、Verify Code

package interview.test;

public class TestJavaGrammer {
    static
    {
        System.out.println("father static!!!");
    }

    {
        System.out.println("father NaN Static");
    }

    TestJavaGrammer(){
        System.out.println("father Constructor");
    }
}

class Child extends TestJavaGrammer{
    static
    {
        System.out.println("child static!!!");
    }

    {
        System.out.println("child NaN Static");
    }

    Child(){
        System.out.println("child Constructor");
    }

    public static void main(String[] args) {
        new Child();
    }
}

上一篇 下一篇

猜你喜欢

热点阅读