#include<iostream>
using namespace std;
class Base
{
public:
void show() { cout<<" In Base \n"; }
};
class Derived: public Base
{
public:
void show() { cout<<"In Derived \n"; }
};
int main(void)
{
Base *bp = new Derived;
bp->show(); // RUN-TIME POLYMORPHISM
return 0;
}
In the above code, show()
is declared in the base class and is overriden in the derived class. The base class pointer bp
points to a derived class object. Now, when bp
to call the non virtual show()
function.
Output:
In Base
But, bp
points to derived class, so why the base's function is called rather than the derived class function?