Polymorphism in Java | Java Tutorial

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

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment

Share via
Copy link
Powered by Social Snap