java父子类方法的执行顺序

213 阅读1分钟
public class Father {
     static String name = "father name";

    static {
        System.out.println("Father static filed");
    }

    {
        System.out.println("Father 普通 filed");
    }

    public Father() {
        System.out.println("Father 构造函数");
    }

    public void say() {
        System.out.println("father say hi");
    }

    public void sayHello() {
        System.out.println("father say hello");
    }
}
public class Son extends Father {
    static {
        System.out.println("son static filed");
    }

    {
        System.out.println("son 普通 filed");
    }

    public Son() {
        System.out.println("son 构造函数" + name);
    }

    public void say() {
        System.out.println("son say hi");
    }
}
public class Test {
    public static void main(String[] args) {
        Son son = new Son();
    }
    //Father static filed
    //son static filed
    //Father 普通 filed
    //Father 构造函数
    //son 普通 filed
    //son 构造函数father name
}