C++ Polymorphism

C++ Polymorphism


C++ Polymorphism
Polymorphism is a feature of Object Oriented Programming that is the process of representing one form in multiple forms is known as Polymorphism. Here one form represents original form or original method always resides in base class multiple forms represent overridden methods which resides in driven classes.
Polymorphism is derived from two Greek words: poly and morphs. The word “poly” means many and “morphs” means forms.
Types of polymorphism
Introduction to Polymorphism in C#
 
  • Static Polymorphism is also known as early binding and compile-time polymorphism. In static polymorphism memory will be allocated at compile-time.
  • Dynamic polymorphism also as late binding and run-time polymorphism. In static polymorphism memory will be allocated at compile-time.
C++ Compile Time Polymorphism
In this method object is bound to the function call at the compile time.
Example- The simple program for C++ Compile Time Polymorphism is as follows:
 
Output
Example- The simple program for C++ Runtime Polymorphism is as follows:
C++ Runtime Polymorphism
In this method object is bound to the function call only at the run time

 
Example- The simple program for C++ Runtime Polymorphism is as follows:

      Output