Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation and Management

Authors: Carlos Coronel, Steven Morris

11th edition

9781305323230, 1285196147, 1305323238, 978-1285196145

More Books

Students also viewed these Programming questions

Question

=+a. What is P(xn11 , x1)?

Answered: 1 week ago

Question

=+c. What is P(xn11 , y1)? What is P(xn11 . yn)?

Answered: 1 week ago