30.2k views
0 votes
If I have an Animal superclass with a Mammal subclass, both concrete and both having a method called eat() with identical signatures and return types, polymorphism means:________.

a. the Animal version of eat() will be called, regardless of the static/dynamic type.
b. the Mammal version of eatſ) will be called, regardless of static/dynamic.
c. the dynamic type of the reference will determine which of the methods to call.
d. the static type of the reference will determine which of the methods to call.

1 Answer

3 votes

Answer:

(c) the dynamic type of reference will determine which of the methods to call.

Step-by-step explanation:

Polymorphism in Object Oriented Programming typically means the same method name can cause different actions depending on which object it is invoked on. Polymorphism allows for dynamic binding in that method invocation is not bound to the method definition until the program executes.

So in the case of Animal superclass and Mammal subclass, both having a method called eat() with identical signatures and return types, depending on which reference, the correct method eat() will be called dynamically upon execution.

For example, if we have the following;

================================

Mammal mammal = new Animal();

mammal.eat()

================================

The eat() method that will be called is the one in the Mammal subclass.

However, if we have;

================================

Animal animal = new Animal();

animal.eat()

================================

The eat() method of the Animal superclass will be called.

User TheWaveLad
by
6.6k points