Define a class ABC. Derive two classes BBC and KBC from ABC. All the classes contains same member function name as display(). The base class pointer always holds the derived class objects.
a) Write a program such that base class pointer or reference will always access/call the base version of the members available in derived class, do not have any access to the derived class members.
b) Write a program such that base class pointer or reference will always access/call the derived version of the members available in derived class, do not have any access to the base class members.
Write down the concepts used for bit a) and b) separately.
(Pure Virtual Function) Write the above program by modifying by making display() as pure virtual function.
#include <iostream>
using namespace std;
class ABC
{
public:
virtual void display() = 0;
};
class BBC : public ABC
{
public:
void display()
{
cout << "Derived class\n";
}
};
class KBC : public ABC
{
public:
void display(){
cout<<"KBC called\n";
}
};
int main()
{
ABC *b;
BBC dobj;
b = &dobj;
b->display();
}
Comments
Leave a comment