Polymorphism in Java

Polymorphism allows us to perform a task in multiple ways. Let’s break the word Polymorphism and see it, ‘Poly’ means ‘Many’ and ‘Morphos’ means ‘Shapes’.

Let’s see an example. Assume we have four students and we asked them to draw a shape. All the four may draw different shapes like Circle, Triangle, and Rectangle.

Polymorphism In Java

We will see detailed explanation with some example programs about Polymorphism in the post related to Polymorphism.

There are two types of Polymorphism in Java

1. Compile time polymorphism (Static binding) – Method overloading
2. Runtime polymorphism (Dynamic binding) – Method overriding

We can perform polymorphism by ‘Method Overloading’ and ‘Method Overriding’

I recommend you to go through the following posts.

Method Overloading: (Static Polymorphism/Compile time polymorphism)

Method Overriding: (Dynamic Polymorphism/Run time polymorphism)

Let’s see some practical examples of both compile time polymorphism and run time polymorphism.

Compile Time Polymorphism:

Output:

Run Time Polymorphism:

Output:

Must Read: Java Tutorial

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap