Write a c++ program to implement method overriding

#include<iostream>

using namespace std; 

class base

{

public:

void virtual show()

{

cout<<“baseclass”;

}

};

class derived:public base

{

public:

void show()

{

cout<<“derived class”;

}

};

int main()

{

base *b;

derived d;

b=&d;

b->show();

return(0);

}

Output:

Derived class

Leave a Comment

Your email address will not be published. Required fields are marked *