C++ Program to demonstrate Run time polymorphism

By | January 3, 2017

Demonstrate Run time polymorphism


Write a C++ Program to demonstrate Run time polymorphism. Here’s a Simple C++ Program to demonstrate Run time polymorphism in C++ Programming Language.


Run time polymorphism


  • In place of static binding, one would like a binding method that is capable of determining which function should be invoked at run-time, on the basis of object type making call.
  • This type of binding is knows as late or dynamic binding, since the selection of the appropriate function is done dynamically at run-time.
  • To achieve dynamic binding, C++ offers a special feature known as virtual function.
  • A virtual function specification tells the compiler to create a pointer to a function but not to fill in the value of the pointer until the function is actually called.
  • Then at run-time and on the basis of the object making the call, the appropriate function address is used.
  • When a function with same name, same number of arguments and same type of arguments is used in both the base class and derived classes, the function in the base class can be made virtual by using a keyword virtual, preceding the function declaration.
  • For example, in the previous program, the function Display() in the base class B can be made virtual, by using the declaration as:
  • virtual void Display(void) ;

  • When a function is made virtual, C++ determines which function to use at run-time based on the type of the object pointed to by the base class pointer, rather than the type of the pointer.

Below is the source code for C++ Program to demonstrate Run time polymorphism which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


 


OUTPUT : :



Above is the source code and output for C++ Program to demonstrate Run time polymorphism which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

Leave a Reply