Difference between revisions of "Polymorphism"

From JholJhapata
Line 1: Line 1:
 
'''Polymorphism''' meaning "one name many forms", which is also referred to as the third pillar of o'''bject-oriented programming'''. "Poly" means many and "morph" means forms. Polymorphism provides the ability to a class to have multiple implementations with the same name.
 
'''Polymorphism''' meaning "one name many forms", which is also referred to as the third pillar of o'''bject-oriented programming'''. "Poly" means many and "morph" means forms. Polymorphism provides the ability to a class to have multiple implementations with the same name.
 
== Types of Polymorphism ==
 
== Types of Polymorphism ==
 +
[[File:Polymorphism.png|thumb|Polymorphism]]
 
Polymorphism can be static or dynamic. In '''static polymorphism''', the response to a function is determined at the compile time. In '''dynamic polymorphism''', it is decided at run-time.
 
Polymorphism can be static or dynamic. In '''static polymorphism''', the response to a function is determined at the compile time. In '''dynamic polymorphism''', it is decided at run-time.
 
== Static Polymorphism ==  
 
== Static Polymorphism ==  
 +
Static polymorphism is also known as Early Binding. We can achieve this by Method overloading. In overloading, the method / function has a same name but different signatures (types and/or the number of arguments and/or order of arguments). It is also known as Compile Time Polymorphism because the decision of which method is to be called is made at compile time.
 
=== Static Polymorphism Example ===
 
=== Static Polymorphism Example ===
 
== Dynamic Polymorphism ==
 
== Dynamic Polymorphism ==
 
=== Dynamic Polymorphism Example ===
 
=== Dynamic Polymorphism Example ===

Revision as of 06:15, 15 August 2019

Polymorphism meaning "one name many forms", which is also referred to as the third pillar of object-oriented programming. "Poly" means many and "morph" means forms. Polymorphism provides the ability to a class to have multiple implementations with the same name.

Types of Polymorphism

Polymorphism

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.

Static Polymorphism

Static polymorphism is also known as Early Binding. We can achieve this by Method overloading. In overloading, the method / function has a same name but different signatures (types and/or the number of arguments and/or order of arguments). It is also known as Compile Time Polymorphism because the decision of which method is to be called is made at compile time.

Static Polymorphism Example

Dynamic Polymorphism

Dynamic Polymorphism Example