Polymorphism : provides different-different behaviour to same object

Polymorphism contains two words : Poly and Morphism . Poly means many and morphism means behaviour.

The ability of an object to take on different forms is known as polymorphism.Polymorphism is the capability of a method to do different things based on the object that it is acting upon.

For example : If we take the example of wikipedia we can see that we can see the content in english or same content we can see in the hindi or other languages,that mean application is same but showing the different-different behaviour.

We can see the most common use of polymorphism in OOP so, when a parent class reference is used to refer to a child class object.java course in bangalore

Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.

We know thatonly possible way to access an object is through a reference variable. A reference variable can be of only one type. Once declared, the type of a reference variable cannot be changed.

The reference variable can be reassigned to other objects provided that it is not declared final. The type of the reference variable would determine the methods that it can call on the object.

We create the reference variable for class as well as for interface.java training center bangalore

Types of Polymorphism:

[1]Compile Time Polymorphism

[2]Run Time Polymorphism

Compile Time Polymorphism: When method binding happens at compile time is known as compile time polymorphism or static binding.

Method binding means when method call get attach with method body.

For achieving Static binding Method Overloading is necessary:

Note: Method Overloading means same method name but differs in number of parameters ,types of parameters and position of parameters.

Run Time Polymorphism : When method binding happens at run time is known as run time polymorphism or dynamic binding.

For getting dynamic binding inheritance,overriding and upcasting is necessary.

If any one property not there we can’t get the run time polymorphism.

Best core java training in bangalore


class Car{

void run( ){



class Audi extends car{

void run()


System.out.println(“running safely”);


public static void main(String args[])


Car c=new Audi();//upcasting




Output : running safely

In above example, we are creating two classes Car and Audi. Audi class extends Car class and overrides its run() method. We are calling the run method by the reference variable of Parent class. Since it refers to the subclass object and subclass method overrides the Parent class method, subclass method is called at runtime. Advance java training in bangalore

class Vehicle
void noOfTyre(int num)
System.out.println (“The no of tyre in cycle is =”+num);
void noOfTyre(int num1, int num2)
System.out.println (“The no of tyre in Car=”+(num1+num2));

class Tyre
public static void main (String args [])
Vehicle v=new Vehicle();
v. noOfTyre(2)
v. noOfTyre(2,2)

Need Of Polymorphism:
 a) It gets useful when you have different types of objects and can write classes that can work with all those different types because they all adhere to the same API.

b)It’s used when an entity of your conceptual project can be seen as the specialization of another entity.java/j2ee classes bangalore
 This is the short description about Polymorphism .To know more about Core and Advance java attend classes in Infocampus Software Training institute.

Author :

Infocampus provides java course in Bangalore with lesser fees.It provides Core & Advance java training which is mainly focused on complete practical sessions. Free job assistance will be provided. Pay fees in installments. Mock exams and mock interviews conducted after the completion of course. For more information on java/j2ee classes bangalore contact @ 9738001024 or visit http://www.infocampus.co.in/java-training-bangalore.html

Show your support

Clapping shows how much you appreciated Infocampus’s story.