继承中子父类的静态代码块与构造方法的执行顺序

输出程序运行后的打印结果:

复制代码
    class Father{
        static {
            System.out.print("1");
        }
        Father(){
            System.out.print("3");
        }
    }
    class Son extends Father{
        static {
            System.out.print("2");
        }
        Son(){
            System.out.print("4");
        }
        public static void main(String[] args) {
            Father s = new Son();
            s = new Son();
        }
    }
复制代码

打印后的结果为:123434

posted @   junlu  阅读(62)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示