Question
Write the output of given code segments and explain it logically. 1 . #include using namespace std; class Base { public: virtual void show() {
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;
}
Step by Step Solution
3.46 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
1 include usin...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Database Systems Design Implementation and Management
Authors: Carlos Coronel, Steven Morris
11th edition
9781305323230, 1285196147, 1305323238, 978-1285196145
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App