I'm working on a project atm that requires me to use polimorphism concepts.
I have this question:
Imagine I have an interface that represents all mammals, then I create the following sub-classes: Human and Whale.
Imagine now I wanted to create some humans and some whales on my program, I would keep them in a array of mammals.
Thing is, the sub-class Human
has the solveMathProblem()
method, while the Whale
class doesn't have it, therefore neither does the Mammals.
How could I use that method in the array?(For example: mammals[2].solveMathProblem();
)
That won't work since the solveMathProblem()
isn't specified in the Mammals Interface because only humans can do it)
What can I do to make that work?