[Solved] Having an issue with inheritance. Need to call subclass method from a manager class?


Make your Racer superclass abstract and include an abstract method called move. Then when you extend Racer to each of the racer types, you can write unique methods that all return a value indicating the distance to move.

This enables you to create a list of racers and call the move method directly from the array

like this

Racer racerLists[] = new Racer[4];
racerLists[0] = new Motorcycle();
racerLists[1] = new Car();
racerLists[2] = new Bike();
racerLists[4] = new Runner();

for(int i=0; i<racerLists.length; i++)
{
    racerLists[i].move();
}

each racer will have their unique move method called.

Don’t forget to mark this as an answer if this answers your question.
Thanks

3

solved Having an issue with inheritance. Need to call subclass method from a manager class?