New Year Sale 2026! 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 1 Question 7 Discussion

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

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

public:

A() { cout << "A0 ";}

A(string s) { cout << "A1";}

};

class B : public A {

public:

B() { cout << "B0 ";}

B(string s) { cout << "B1 ";}

};

class C : private B {

public:

C() { cout << "C0 ";}

C(string s) { cout << "C1 ";}

};

int main () {

B b1;

C c1;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Ahmed
3 months ago
This seems off, I doubt it prints that way.
upvoted 0 times
...
Mona
4 months ago
Wait, does it really not call A1 at all?
upvoted 0 times
...
Tamesha
4 months ago
Nah, I’m pretty sure it’s just B0 B1.
upvoted 0 times
...
Rozella
4 months ago
I think it should be A0 B0 C0 for sure!
upvoted 0 times
...
Rhea
4 months ago
It prints: A0 B0 C0
upvoted 0 times
...
Muriel
4 months ago
I thought the output would include B1 since there's a string constructor in B, but I guess it only gets called if you create a B with a string?
upvoted 0 times
...
Timmy
5 months ago
I practiced a similar question where the base class constructor was called first. I feel like it should print A0 B0 and then C0, but I could be wrong.
upvoted 0 times
...
Ronny
5 months ago
I'm not entirely sure, but I remember something about private inheritance affecting how constructors are called. Does that mean C's constructor won't call B's?
upvoted 0 times
...
Reuben
5 months ago
I think when you create an object of class B, it should call the constructor of A first, right? So maybe it prints A0 B0?
upvoted 0 times
...
William
5 months ago
This is a tricky one. The private inheritance in class C is throwing me off a bit. I'll need to review the rules around constructor calls and inheritance to make sure I understand what's happening here.
upvoted 0 times
...
Samira
5 months ago
I'm a bit confused by the private inheritance in class C. Does that affect the constructor calls in some way? I'll have to think through the order of constructor invocations to solve this.
upvoted 0 times
...
Alfred
5 months ago
Hmm, this looks like it's testing our understanding of inheritance and constructor calls. I'll need to carefully trace the object creation and constructor invocations to figure out the correct output.
upvoted 0 times
...
Mendy
5 months ago
Okay, I think I've got it. Since class B is publicly inherited from A, the B constructors will call the A constructors. And since class C is privately inherited from B, the C constructors will only call the default B constructor. The output should be straightforward to determine.
upvoted 0 times
...
Pamella
5 months ago
I feel pretty confident that a Visual Prototype is the way to go here. It would give the customer a clear visual representation of the new online experience, which seems like the most effective way to communicate the changes.
upvoted 0 times
...
Isaiah
5 months ago
This seems pretty straightforward. The focus group was used to test the customer experience, so I'd go with option A - Focus group.
upvoted 0 times
...
Ammie
5 months ago
Okay, let's see. We need to create three interfaces, so we'll want to use a loop to do that. I'm leaning towards A, 'with_items', since that's the most straightforward way to iterate over a list of interface names.
upvoted 0 times
...
Leonida
10 months ago
Ah, the age-old constructor conundrum strikes again! I'm going with C) for this one. After all, who doesn't love a good old-fashioned 'A no parameters' followed by a 'B string parameter'? It's like a symphony of C++ goodness.
upvoted 0 times
Diego
8 months ago
Great, let's go with C) then.
upvoted 0 times
...
Rolf
9 months ago
That's what I was thinking too. C) it is.
upvoted 0 times
...
Daniela
9 months ago
Yeah, I agree. It should print: A no parameters B string parameter.
upvoted 0 times
...
Chaya
9 months ago
I think C) is the correct answer.
upvoted 0 times
...
...
Deangelo
10 months ago
Wait, wait, wait... is the answer D) It prints: A no parametersA no parameters? I'm pretty sure that's wrong, but I can't quite figure out the right answer. Maybe I should have paid more attention in that inheritance lecture.
upvoted 0 times
...
Dustin
10 months ago
Ha! This is a classic constructor chaining problem. The answer is clearly C) It prints: A no parametersB string parameter. I've seen this kind of question before, it's all about understanding the order of constructor calls.
upvoted 0 times
Joaquin
9 months ago
Understanding constructor chaining is key in this scenario.
upvoted 0 times
...
Dell
9 months ago
Yes, the answer is definitely C) It prints: A no parametersB string parameter.
upvoted 0 times
...
Antonio
9 months ago
I agree, it's all about the order of constructor calls.
upvoted 0 times
...
...
Von
10 months ago
Hmm, this question is tricky. I think the answer is B) It prints: A string parameterA no parametersB string parameterA object A parameter. But I'm not sure, I might need to double-check the inheritance rules in C++.
upvoted 0 times
...
Kirby
10 months ago
The correct answer is C) It prints: A no parametersB string parameter. The constructors of the base classes are called in the order of inheritance, so the output should be A0 B1 C0.
upvoted 0 times
Karma
9 months ago
So the output should be A0 B1 C0.
upvoted 0 times
...
Rocco
9 months ago
Oh, I see. The constructors of the base classes are called in the order of inheritance.
upvoted 0 times
...
Daryl
10 months ago
I think the correct answer is C) It prints: A no parametersB string parameter.
upvoted 0 times
...
...
Huey
11 months ago
Hmm, that makes sense too. Let's see what others think before deciding.
upvoted 0 times
...
Xochitl
11 months ago
I disagree, I believe the answer is B because the code creates objects of class B and class C with string parameters.
upvoted 0 times
...
Huey
11 months ago
I think the answer is A because the code creates an object of class B without any parameters.
upvoted 0 times
...
Cathrine
11 months ago
Hmm, I see your point. But I still think option A makes more sense based on the code logic.
upvoted 0 times
...
Kenneth
11 months ago
I disagree, I believe the correct answer is C. It prints: A no parametersB string parameter.
upvoted 0 times
...
Cathrine
11 months ago
I think the answer is A. It prints: A no parametersA no parametersB string parameter.
upvoted 0 times
...

Save Cancel