package com.rk.www.TestForInterView; /** * static block,constructor,parent,child * 执行顺序: * 1,父类的静态代码块 * 2,子类的静态代码块 * 3,父类的构造方法 * 4,子类的构造方法 * * 总结:静态代码块在类加载时优先执行,优先于构造方法在类的对象生成之前执行,且只执行一次 * @author jacky * */ public class OrderTest { public static void main(String[] args){ new Child(); new Child(); } } class Parent{ static{ System.out.println("parent static block"); } public Parent(){ System.out.println("parent constructor"); } } class Child extends Parent{ static{ System.out.println("child static block"); } public Child(){ System.out.println("child constructor"); } }