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

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;}
C) cout << A::y << A::z;
A) cout << y << z;
B) cout << y << A::z;
D) cout << B::y << B::z;

C++ Institute CPA-21-02 Exam - Topic 4 Question 54 Discussion

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

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;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Marion
5 days ago
Option B is the right choice!
upvoted 0 times
...
Gilma
10 days ago
Not sure about that, seems tricky.
upvoted 0 times
...
Zona
15 days ago
Totally agree with B!
upvoted 0 times
...
Kimi
20 days ago
Wait, does that mean A::z is different from B::z?
upvoted 0 times
...
Alona
25 days ago
I think it's actually option D.
upvoted 0 times
...
Malcolm
1 month ago
Option B is the right choice!
upvoted 0 times
...
Silvana
1 month 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.
upvoted 0 times
...
Quinn
1 month ago
I practiced a similar question, and I feel like option D could work since it prints the values from class B directly.
upvoted 0 times
...
Beata
2 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.
upvoted 0 times
...
Jacklyn
3 months ago
I think option B might be correct because it accesses the public variable from class A.
upvoted 0 times
...

Save Cancel