What is polymorphism in java with example, Static & Dynamic Polymorphism example

Polymorphism in java example, Static & Dynamic Polymorphism example

 

Polymorphism is a feature that allows one interface to be used for a general class of actions when one task is performed by different ways i.e. known as polymorphism.  

What is polymorphism in java with example, Static & Dynamic Polymorphism example

The behaviour depends on the types of data used in the operation. It plays an important role in allowing objects having different internal structures to share the same external interface.

In java, we use method overloading and method overriding to achieve polymorphism. 

For Example 

Cat speaks meaw, dog barks woof etc


Types of Polymorphism:

1. Static Polymorphism and 

2. Dynamic Polymorphism

1. Static Polymorphism (Function Overloading) – Function overloading if we have more than one function having same name with different prototypes (parameters) then it is also called function overloading.

2. Dynamic Polymorphism (Function Overriding) – Function overriding is just easy to say if sub class or child class has the same method or function declared in the parent class that types of method is called function or method overriding.

Declaring a method in subclass (child class) which function is already declared in parent class is known as method overriding.

 


Post a Comment

Previous Post Next Post