繼承類的構建過程是向外擴散的,子類初始化了,父類一定也初始化了
代碼如下:
class Art{
Art(){
System.out.println("Art");
}
}
class Drawing extends Art{
Drawing(){
System.out.println("Drawing");
}
}
public class Cartoon extends Drawing {
Cartoon(){
System.out.println("Cartoon");
}
public static void main(String[] args) {
Art cartoon = new Cartoon();
}
}
輸出為:
代碼如下:
Art
Drawing
Cartoon