Answer to Question #213953 in C++ for ali

Question #213953

Write output of given code segments and explain it logically, answer without explanation will be awarded zero marks. 

a)  

#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;

}


1
Expert's answer
2021-07-05T13:32:46-0400

Output

In Derived

In Derived


Explanation

The virtual function in the base class is overridden by the show function in the base class hence the "In Derived" will be printed in both cases


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS