Java对象初始化顺序

package com.interview.qa;

public class InitialOrderTest {
    public static String staticField = "静态变量";
    public String fieldVar = "变量";
    static{
        System.out.println("静态初始化块.");
        System.out.println(staticField);
    }
    {
        System.out.println("普通代码块.");
        System.out.println(fieldVar);
    }
    public InitialOrderTest(){
        System.out.println("构造器.");
    }
    public static void main(String[] args) {
        new InitialOrderTest();
    }

}

你可能感兴趣的:(Java对象初始化顺序)