Question OOP-CTOR-0036
EasyWhat is the output of this code?
#include <iostream>
using namespace std;
class P {
int x, y;
public:
P(int a) : x(a), y(a * 2) {}
int sum() { return x + y; }
};
int main() {
P p(4);
cout << p.sum();
}
- A.
8
- B.
12
- C.
Sign up free to see the answer and a step-by-step explanation.