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 7 Question 57 Discussion

Which code, inserted at line 10, generates the output "2?1"?#include #include using namespace std;class A {protected:int y;public:int z;};//insert code herepublic:void set() {y = 2;z = 3;}void Print() { cout
B) class B : public A {
A) class B : private A {
C) class B : protected A {
D) class B {

C++ Institute CPA-21-02 Exam - Topic 7 Question 57 Discussion

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

Which code, inserted at line 10, generates the output "2?1"?

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int z;

};

//insert code here

public:

void set() {

y = 2;

z = 3;

}

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

};

int main () {

B b;

b.set();

b.z = ?1;

b.Print();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Nakisha
5 days ago
Really? I thought it would be C for some reason.
upvoted 0 times
...
Teri
10 days ago
Wait, how does that even print "2?1"?
upvoted 0 times
...
Pok
15 days ago
Definitely B, since it allows access to z.
upvoted 0 times
...
Tish
20 days ago
I think A would work too, but not sure.
upvoted 0 times
...
Laquanda
25 days ago
Option B is the right choice!
upvoted 0 times
...
Jackie
1 month ago
I feel like option D could work too, but then we wouldn't have access to the protected member y at all.
upvoted 0 times
...
Della
1 month ago
I'm a bit confused about the protected members. Would option C allow us to access y in the derived class?
upvoted 0 times
...
Vallie
1 month ago
I remember practicing a similar question where we had to determine access levels in inheritance. I think option A might restrict access too much.
upvoted 0 times
...
Bethanie
2 months ago
I think option B makes sense because it allows access to the public members of class A, but I'm not entirely sure if that's what we need for the output.
upvoted 0 times
...

Save Cancel