Introduction to Polymorphism

Get an overview of 'polymorphism'.

What is polymorphism?

Polymorphism is the property of something having many forms. Any object that can pass more than one “is-a” test is considered to be polymorphic. In Java, all objects are polymorphic since any object will pass the is-a test for their own type and the class Object.

Types of polymorphism

  • Static polymorphism
  • Dynamic polymorphism

Static polymorphism

Linking a method with an object during compile time is an example of static polymorphism. Implementing multiple methods, within the same class, that use the same name but a different set of parameters (method overloading) is also an example of static polymorphism. We have already covered it in detail.

Dynamic polymorphism

This form of polymorphism doesn’t allow the compiler to determine the executed method. Within an inheritance hierarchy, a subclass can override a method of its superclass. It enables us to customize or completely replace the behavior of that method in the subclass. This is called method overriding. We’ll cover it in detail in the next lesson.

Both methods, implemented by the superclass and subclass, share the same name and parameters but provide different functionality. At runtime, the method in the actual object type is executed.


Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy