I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend class Airplane.
I also have an interface Measurable, and two classes that implement it - People and Containers.
So, Airplane can do many things on its own, and there is a method which allows measurable things to be added to the airplane (called addAMeasurableThing). The only difference between PassengerAirplane/CargoAirplane and just an Airplane is that addAMeasurableThing should only accept People / Containers, and not any kind Measurable things. How do I implement this?
I tried doing:
Airplane class:
public abstract Airplane
addAMeasurableThing (Measurable m, int
position);
PassengerAirplane class:
public Airplane addAMeasurableThing
(Measurable m, int position) { if (m
instanceof People)...
CargoAirplane class:
public Airplane addAMeasurableThing
(Measurable m, int position) { if (m
instanceof Containers)...
But when I was debugging it, I've noticed that addAMeasurableThing in the CargoAirplane class never gets called, because both methods have the same signature. So how can the appropriate PassengerAirplane/CargoAirplane's addAMeasurableThing be called, depending on the type of Measurable thing that is being passed on?
Thanks!