Write the output of given code segments and explain it logically. 1 . #include using namespace std;
Fantastic news! We've Found the answer you've been seeking!
Question:
Write the output of given code segments and explain it logically.
1.
#include
using namespace std;
class Base
{
public:
virtual void show() { cout<<" In Base "; }
};
class Derived: public Base
{
public:
void show() { cout<<"In Derived "; }
};
int main(void)
{
Base *bp = new Derived;
bp->show();
Base &br = *bp;
br.show();
return 0;
}
2.
#include
using namespace std;
class Base
{
public:
virtual void show() { cout<<" In Base "; }
};
class Derived: public Base
{
public:
void show() { cout<<"In Derived "; }
};
int main(void)
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
bp = &b;
bp->show();
return 0;
}
Related Book For
Database Systems Design Implementation and Management
ISBN: 978-1285196145
11th edition
Authors: Carlos Coronel, Steven Morris
Posted Date: