子类创建时原来也要创建父类
class Art {
public Art() {
System.out.println("Art constructor");
}
}
class Drawing extends Art{
public Drawing() {
System.out.println("Drawing constructor");
}
}
class Cartoon extends Drawing{
public Cartoon(){
System.out.println("Cartoon construtor");
}
public static void main(String[] args){
Cartoon x = new Cartoon();
}
}
会得到这样得结果:
Art constructor
Drawing constructor
Cartoon construtor