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 4 Question 54 Discussion

Posted by Dottie on May 12, 2026 at 02:24 PM

Which code, inserted at line 19, generates the output "23"?

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

A() { x=1; y=2; z=3; }

};

class B : public A {

string z;

public:

int y;

void set() { y = 4; z = "John"; }

void Print() {

//insert code here

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Suggested Answer: C

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
22 comments · newest first
SH
Shala 5 days ago
Why B?
FA
Fanny 10 days ago
I think option B is the right choice.
BI
Billye 15 days ago
Exactly! B gives "23" because of A::z.
HU
Hui 20 days ago
D? But it prints B's z, not A's.
GW
Gwen 25 days ago
I feel like D could work too.
ST
Stephania 1 month ago
It accesses the base class's z.
HU
Hui 1 month ago
Why B?
ST
Stephania 1 month ago
I think option B is the right choice.
VI
Vicki 2 months ago
I’m not so sure about that, seems tricky.
CH
Chara 2 months ago
No way, it's definitely A!
JA
Janessa 2 months ago
Wait, does that mean A::z is 3?
MA
Marjory 2 months ago
I think it's actually D.
MA
Marion 2 months ago
Option B is the right choice!
GI
Gilma 2 months ago
Not sure about that, seems tricky.
ZO
Zona 3 months ago
Totally agree with B!
KI
Kimi 3 months ago
Wait, does that mean A::z is different from B::z?
AL
Alona 3 months ago
I think it's actually option D.
MA
Malcolm 3 months ago
Option B is the right choice!
SI
Silvana 3 months ago
I'm a bit confused about the protected members. Does option A even work? I thought protected members couldn't be accessed like that.
QU
Quinn 3 months ago
I practiced a similar question, and I feel like option D could work since it prints the values from class B directly.
BE
Beata 4 months ago
I'm not sure, but I remember something about scope resolution. Maybe option C is the right choice since it uses A::z.
JA
Jacklyn 5 months ago
I think option B might be correct because it accesses the public variable from class A.
0/2000 characters

Save Cancel