Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 432 Bytes

类的初始化顺序.md

File metadata and controls

25 lines (25 loc) · 432 Bytes

####类的初始化顺序


package lintcode;
class A {
    public A(String msg) {
        System.out.println(msg);
    }
}
class B {
    static A a1 = new A("a1");
    A a2 = new A("a2");
    static {
        a1 = new A("a3");
    }
    public B() {
        a2 = new A("a4");
    }
}
public class Init {
    public static void main(String[] args) {
        B b = new B();
    }
}

输出结果为:a1a3a2a4