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;
}
Suggested Answer: B
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
28 comments · newest first
CA
Carolynn
14 days ago
Let's hope the exam has similar questions!
VA
Valentine
19 days ago
Yes, it outputs "2?1" correctly.
BE
Bette
24 days ago
So, B is the clear winner here.
RO
Rodrigo
29 days ago
Right, B gives us that access.
CA
Carolynn
1 month ago
Exactly! We need z to be accessible.
VA
Valentine
1 month ago
A is private, so z can't be accessed.
BE
Bette
1 month ago
But what about option A?
RO
Rodrigo
2 months ago
I agree, B makes sense.
VA
Valentine
2 months ago
Because it allows access to public members.
CA
Carolynn
2 months ago
Why B?
VA
Valentine
2 months ago
I think option B is the right choice.
CY
Cyril
2 months ago
Let’s go with B then!
CA
Carry
3 months ago
I agree, B is clear. It’s straightforward.
DE
Deeanna
3 months ago
True, B gives us the output "2?1".
PE
Percy
3 months ago
Exactly, we need public access for z. B is the best fit.
CY
Cyril
3 months ago
But A won't let us access z directly.
DE
Deeanna
3 months ago
I’m leaning towards A. Private inheritance could work too.
PE
Percy
3 months ago
Yeah, B makes sense. It sets z to 1.
CY
Cyril
4 months ago
I think option B is the right choice. It allows access to z.
NA
Nakisha
4 months ago
Really? I thought it would be C for some reason.
TE
Teri
4 months ago
Wait, how does that even print "2?1"?
PO
Pok
4 months ago
Definitely B, since it allows access to z.
TI
Tish
4 months ago
I think A would work too, but not sure.
LA
Laquanda
4 months ago
Option B is the right choice!
JA
Jackie
5 months ago
I feel like option D could work too, but then we wouldn't have access to the protected member y at all.
DE
Della
5 months ago
I'm a bit confused about the protected members. Would option C allow us to access y in the derived class?
VA
Vallie
5 months 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.
BE
Bethanie
5 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.