Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - Topic 6 Question 58 Discussion

What happens when you attempt to compile and run the following code?#include using namespace std;class A {public:int x;A() { x=0;}};class B : protected A {public:int y;using A::x;B(int y) {this?>y = y;}void Print() { cout
A) It prints: 05
B) It prints: 0
C) It prints: 5
D) It prints: 15

C++ Institute CPA-21-02 Exam - Topic 6 Question 58 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 58
Topic #: 6
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class A {

public:

int x;

A() { x=0;}

};

class B : protected A {

public:

int y;

using A::x;

B(int y) {this?>y = y;}

void Print() { cout << x << y; }

};

int main () {

B b(5);

b.Print();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Yoko
4 days ago
I think the constructor for B isn't setting x correctly, so it might just print 0.
upvoted 0 times
...

Save Cancel