Polymorphism Is The Ability of An Object To Take On Many Forms
Polymorphism Is The Ability of An Object To Take On Many Forms
Example
Now, the Deer class is considered to be polymorphic since this has multiple inheritance.
Following are true for the above examples −
Example
All the reference variables d, a, v, o refer to the same Deer object in the heap.
Virtual Methods
In this section, I will show you how the behavior of overridden methods in Java allows you
to take advantage of polymorphism when designing your classes.
We already have discussed method overriding, where a child class can override a method
in its parent. An overridden method is essentially hidden in the parent class, and is not
invoked unless the child class uses the super keyword within the overriding method.
Example