Write output of given code segments and explain it logically, answer without explanation will be awarded zero marks.
#include<iostream>
using namespace std;
class Base
{
public:
virtual void show() { cout<<" In Base \n"; }
};
class Derived: public Base
{
public:
void show() { cout<<"In Derived \n"; }
};
int main(void)
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
bp = &b;
bp->show();
return 0;
}
In Derived
In Base
Initially base pointer points to a derived class object. Later it points to base class object
Comments
Leave a comment