Question OOP-POLY-0043
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
class Base {
public:
virtual void print() { cout << "B"; }
};
class Der : public Base {
public:
void print() { cout << "D"; }
};
void call(Base b) { b.print(); }
void callRef(Base &b) { b.print(); }
int main() {
Der d;
call(d);
callRef(d);
}
- A.
BB
- B.
BD
- C.
DB
- D.
DD
Sign up free to see the answer and a step-by-step explanation.