构造方法与构造块的执行顺序(区别于static)

小面试题:在类的实例化时,会调用类的构造块(类中的构造块)和构造方法,无论构造方法在前还是在后,都先执行构造块

class Person{
    public Person(){
        System.out.println("我是无参构造方法");
    }
    {
        System.out.println("我是构造块");
    }
}
public class Test2 {

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

console结果:

我是构造块
我是无参构造方法

原文地址:https://www.cnblogs.com/lbloveab/p/7253537.html