父類:
public class TrainCar extends GCompound{
public TrainCar(double size){
engine = new Engine(size);
add(engine);
}
}
子類:
public class Engine extends TrainCar {
public Engine (double size){ //繼承父類之後,標記這行出錯。如果繼承 GCompound,則無問題。
GPolygon engine = engine(size);
add(engine);
}
}
因為父類沒有默認的構造方法吧
兩種改法:1.父類加上無參數的構造方法
2.public Engine (double size){}方法裡加上super(size);