Polymorphism

The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages. This principle can also be applied to object-oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.

Polymorphism can be demonstrated with a minor modification to the Animal class. For example, a describe() method could be added to the class that describes a specific animal.

To demonstrate polymorphic features in the Java language, extend the Animal class with Dog and Bird classes.

For Dog has special skill is house guarding. And bird could fly 200 MPH.

The Animal Class

The Dog Class

The Bird Class

The Test Class

Run The Application

Right click to the test class; select Run As -> Java Application.

Output