C++ | Virtual Functions | Question 2

Last Updated :
Discuss
Comments
Predict output of the following program C
#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 = new Derived;
    bp->show();

    Base &br = *bp;
    br.show();

    return 0;
}
In Base 
In Base 
In Base 
In Derived
In Derived
In Derived
In Derived
In Base 
Share your thoughts in the comments