Chapter: Programming and Data structures : Object Oriented Programming Concepts

Polymorphism

Polymorphism is one of the most important features of Object Oriented Programming. Polymorphic variables can take up objects or values of different types as values and polymorphic functions and procedures can be used as objects or values of different types.

POLYMORPHISM:

 

Polymorphism is one of the most important features of Object Oriented Programming. Polymorphic variables can take up objects or values of different types as values and polymorphic functions and procedures can be used as objects or values of different types. It refers to exhibiting different behaviour by an instance in different situations.

 

 

 

Polymorphism is implemented through,

 

 

1.     Function overloading

 

2.     Operator overloading.

 

COMPILE TIME AND RUNTIME POLYMORPHISM:

Compile time Polymorphism:

 

·  Compile time Polymorphism also known as method overloading.

 

· Method overloading means having two or more methods with the same name but with different signatures.

Run time Polymorphism:

 

·        Run time Polymorphism also known as method overriding.

 

·        Method overriding means having two or more methods with the same name, same signature but with different implementation.

 

 

Overloading is a form of polymorphism. In case of function overloading, the information regarding which function is to be invoked corresponding to a function call is available at compile time. This is referred to as static binding or compile time polymorphism, as the object is bound with its function call at compile time.

 

 

Run time polymorphism is achieved through virtual functions. The function to be invoked by the instance of a class is known during runtime. The functions are linked with the class during runtime and not during compile time. When a base class pointer points to a sub class instance, instead of invoking subclass function (a function having name similar to that of function of a base class), it always invokes base class version. If the function in the base class is defined as virtual, then it is known during runtime only, which version of the function will be invoked, corresponding to a function call. Since the function is linked after compilation process, it is termed as late binding or dynamic binding or run-time polymorphism.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Programming and Data structures : Object Oriented Programming Concepts : Polymorphism |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.