Answer to Question #213955 in C++ for ali

Question #213955

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

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

    Derived d;

    bp = &d;

    bp->show();

    bp = &b;

    bp->show();

    return 0;

}


1
Expert's answer
2021-07-06T12:17:13-0400

output

In Derived

In Base


explanation

 Initially base pointer points to a derived class object. Later it points to base class object


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