#include <iostream>
using namespace std;
class A
{
public :
void show()
{
cout << "A " << endl;
}
};
class B : public A
{
public :
void show()
{
cout << "B " << endl;
}
};
int main()
{
A *a =NULL;
a->show(); // Prints 'A'
B *b =NULL;
b->show(); // Prints 'B'
}
How is this getting printed and when we inherit show
from A
to B
, how can show()
be called using a B
class object? What exactly happens when inherited A
from B
?