Header Ads

Explain polymorphism and its type

Polymorphism

Polymorphism is an important feature of object-oriented programming language. It is the ability of a message or data to be processed in more than one form. Languages such as ADA that does not support polymorphism are called object-based languages. 

Example:

"T-shirt" is a subclass of "clothes".
Similarly "sweater" and "muffler" are also subclasses of "clothes"
When a message "summer wear" is passed to the superclass "clothes". "sweater" and "muffler" will behave differently in response to the message while "T-shirt"will remain same.


There are basically two types of classification that can further be classified. Let us study the main types of polymorphism:

1. Static binding or compile time polymorphism:
In this form the selection of the function invocation is decided at the time of compilation.It is also known as early binding, meaning that the object is bound to its function call at compile time. It can further be divided into:

  • Function overloading: When there are more than one function of the same name then the function is said to be overloaded. The function overloaded comes under static binding because when the function is called the compiler decides which one of the function is to be used.
  • Operator overloading: In operator overloading, an operator is overloaded so that is gets user defined meaning. 
2. Dynamic binding or run time polymorphism:
In dynamic binding, function is run at the time of execution. It is also known as run time polymorphism where function is linked with the class after the compilation process. The concept of dynamic binding can be achieved with the help of virtual functions.

No comments:

CSE Solved. Powered by Blogger.