"Hello, Amigo! Here are a couple hundred tasks on polymorphism for you."
"Huh? A hundred more exercises?!"
"I'm joking. Just ten. I mean, five."
Whales and cows
In real life you would never confuse a whale and a cow. Sea cows (manatees) are sometimes encountered in Terranian waters, and that's not all you'll see on the planets of the Commonwealth! That said, in programming you can do whatever you want. Correctly write a getter for the Whale class, so that the program displays the phrase, "I'm not a cow. I'm a whale."
Whales, the descendants of cows
In Java, method overriding is a very powerful tool. So we're going to begin to master it immediately through practice. Suppose we have a whale, a descendant of cows. Don't ask us how it happened... let's just say it's a family matter. Override the whale getter so that it doesn't display a message about being a cow.
Render to Caesar the things that are Caesar's
There is no doubt whatsoever that cats and dogs are animals. And their descendants must also be animals. But not just any animals. They should be very specific types of animal - cats and dogs. Don't you agree? In that case, override the getChild method in the Cat and Dog classes, so that cats give birth to cats and dogs to dogs.
Whether it's a bird or a lamp
What do birds and lamps have in common? The fact that birds and lamps can both be objects of their respective classes. And objects can be passed into methods as arguments. In this task, we are going to write a method that determines the type of the object passed to it, and then displays the appropriate message. Cat, Dog, Bird, and Lamp.
Napoleon, a cat breeder, believes that it is vitally important to know how to distinguish between types of animals. Let's help Napoleon out. We'll write a method that determines the class of the object passed to it, and returns one of the following results: "Cow", "Whale", "Dog", or "Unknown Animal".