静态块

作者: 龙剑灵 | 来源:发表于2021-03-21 22:26 被阅读0次
    public class OrderTest {
        public static void main(String[] args) {
            new Child();
        }
    }
    class Parent {
        static String name = "hello";
        static {
            System.out.println("Parent static");
        }
        public Parent() {
            System.out.println("Parent constructor");
        }
    }
    class Child extends Parent {
        static String childName = "world";
        static {
            System.out.println("Child static");
        }
        public Child() {
            super();
            System.out.println("Child constructor");
        }
    }
    

    结果

    Parent static
    Child static
    Parent constructor
    Child constructor
    

    相关文章

      网友评论

          本文标题:静态块

          本文链接:https://www.haomeiwen.com/subject/skfacltx.html