Question OOP-ENC-0010
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
class Person {
int age = 0;
public:
void setAge(int a) { if (a >= 0) age = a; }
int getAge() { return age; }
};
int main() {
Person p;
p.setAge(-50);
cout << p.getAge();
return 0;
}
- A.
-50
- B.
50
- C.
Sign up free to see the answer and a step-by-step explanation.