验证构造块和构造器的执行顺序

原文链接: http://www.cnblogs.com/wdh1995/p/6711278.html
public class Test04
{

    public Test04()
    {
        System.out.println("我是构造器");
    }
    
    {
        System.out.println("我是构造块");
    }
    
    public static void main(String[] args)
    {
        Test04 t1 = new Test04();
    }
    //结论:构造块先于构造器执行
    
}

转载于:https://www.cnblogs.com/wdh1995/p/6711278.html

猜你喜欢

转载自blog.csdn.net/weixin_30892889/article/details/94798901
今日推荐