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

Posted by Wilda on Jul 21, 2026 at 05:17 AM

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;

}

Suggested Answer: A

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
12 comments · newest first
MA
Maryann 1 month ago
I'm leaning towards 15. The constructor might be messing things up.
AN
Angella 1 month ago
I feel like it should print 0. The y isn't set correctly.
DI
Dick 1 month ago
I think it prints 05. The x is initialized to 0.
DI
Diane 2 months ago
Definitely prints 05, that's how inheritance works!
VE
Venita 2 months ago
Wait, how does it even access x like that?
AL
Alishia 2 months ago
No way, it should be 15!
SH
Shawn 2 months ago
I think it should print 0, right?
FR
Francesco 2 months ago
It prints: 05
GL
Glenn 2 months ago
I feel like it should print 05 since x is initialized to 0 and y is set to 5 in the constructor.
SK
Skye 3 months ago
I practiced a similar question where the output was affected by member access. This one seems tricky!
AL
Alease 3 months ago
I'm not entirely sure, but I remember something about protected members. Maybe it won't print y at all?
YO
Yoko 3 months ago
I think the constructor for B isn't setting x correctly, so it might just print 0.
0/2000 characters

Save Cancel