简介

没有答出来, 根据如下代码的运行结果可知, 显示父类的静态代码块, 然后是子类的静态代码块, 然后是父类的普通代码块和构造函数, 接着是子类的普通代码块和构造函数.

code

/**
 * Created by lee on 2021/8/24.
 */
public class Father {
    static {
        System.out.println(("Father F0"));
    }
    {
        System.out.println("Father F1");
    }
    public Father() {
        System.out.println("Father F2");
    }

    public static void main(String[] args) {
        Son s = new Son(22);
    }
}

class Son extends Father{
    static {
        System.out.println("Son S0");
    }
    {
        System.out.println("Son S1");
    }
    public Son(Integer a) {
        super();
        System.out.println("Son S2");
    }
}

answer

Father F0
Son S0
Father F1
Father F2
Son S1
Son S2
posted on 2021-08-24 09:50  HDU李少帅  阅读(50)  评论(0编辑  收藏  举报