class B{
public B(){
System.out.println("B对象被初始化!");
}
}
class C extends B{
public C(){
System.out.println("C对象被初始化!");
}
}
public class Test {
public static void main(String[] args) {
B b = new C();
System.out.println("===============");
C c = new C();
}
}
输出:
B对象被初始化!
C对象被初始化!
===============
B对象被初始化!
C对象被初始化!
可以看到,无论怎样,父类都会先于子类被初始化
标签:初始化,Java,对象,子类,System,public,out From: https://www.cnblogs.com/yaocy/p/16999342.html