如果继承 TrainCar 这是一个问题。如果继承 GCompoud 那很好。哪里错了?
家长:</p>
public class TrainCar extends GCompound{
public TrainCar(double size){
engine = new Engine(size);
add(engine);
}
}
子类:</p>
public class Engine extends TrainCar {
public Engine (double size){ //if inherit TrainCar that's a problem.
//if inherit GCompoud that's well.
GPolygon engine = engine(size);
add(engine);
}
}
Boxcar 继承了 TrainCar,这很好。
在讲义 #31 中:
public class Boxcar extends TrainCar {
public Boxcar(Color color) {
}
http://www-cs-faculty.stanford.edu/~eroberts/courses/cs106a/handouts/30-graphical-structures.pdf