What is Polymorphism?

Polymorphism means many forms.

A single object can refer to the superclass or subclass depending on the reference type which is called polymorphism.

Example: 

public class Manipulation{ 
    //Super class 
    public void add(){ 

    }
}
public class Addition extends Manipulation(){ 
    // Sub class 
    public void add(){ 

    }

    public static void main(String args[]){ 
        
        //Manipulation is reference type and Addition is reference type 
        Manipulation addition = new Addition();

        addition.add(); 

    }
}

Using Manipulation reference type we can call the Addition class “add()” method. This ability is known as Polymorphism.

Polymorphism is applicable for overriding and not for overloading.

Top 50+ Java Interview Questions with Answers

We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates.  Q.1- What is… Read More

4 years ago