This code defines two classes Base and Derived where Derived is derived from Base class publicly. The Base class has an integer data member a and a member function display() which displays the value of a. The Derived class has a member function show() which displays the message "Show of Derived".
In the main function, an object of Derived class is created named d. The integer data member a of Base class is assigned a value of 100. The display() function of Base class is called using the d object which displays the value of a. The show() function of Derived class is called using the d object which displays the message "Show of Derived".
#include <iostream> using namespace std; class Base { public: int a; void display() { cout<<"Display of Base "<<a<<endl; } }; class Derived:public Base { public: void show() { cout<<"Show of Derived"<<endl; } }; int main() { Derived d; d.a=100; d.display(); d.show(); } /* Reuse Polymorphism */To download raw file Click Here
Display of Base 100Show of Derived
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions