Question OOP-POLY-0062
HardWhat is the output of this code?
#include <iostream>
using namespace std;
class Base {
public:
virtual void f(int x = 1) { cout << "B" << x; }
};
class Der : public Base {
public:
void f(int x = 2) override { cout << "D" << x; }
};
int main() {
Der d;
Base &b = d;
b.f();
}
- A.
D1
- B.
B1
- C.
Sign up free to see the answer and a step-by-step explanation.