What if I want to treat ToyTruck a subclass of Truck but I don't want to have all the methods declared in the Truck class?. For example, The Truck class has a method "addGasoline()" but the a ToyTruck do not need Gasoline to work. One solution I get is that I will just Override the "addGasoline()" method and implement it as an empty method. But for me, this not make the ToyTruck to not have a method"addGasoline()". And one more solution I think is do this as a composition, but I don't know where to start and how will I use polymorphism using composition.
Aucun commentaire:
Enregistrer un commentaire