成员变量初始化优先于构造函数的运行

public class test4 {
    public static void main(String[] args) {
        test4 a = new test4();
        System.out.println(a.i);
    }

    public int i = 1;

    public test4 ()
    {
        System.out.println(i);
        i=2;
    }
}

输出结果为:

1
2

Process finished with exit code 0

原文地址:https://www.cnblogs.com/kincolle/p/7237463.html