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 Exam CPA-21-02 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:

Leonida
17 days 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
Chaya
13 hours ago
I think C) is the correct answer.
upvoted 0 times
...
...
Deangelo
19 days 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
22 days 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
...
Von
27 days 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
28 days 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
Daryl
21 days ago
I think the correct answer is C) It prints: A no parametersB string parameter.
upvoted 0 times
...
...
Huey
2 months ago
Hmm, that makes sense too. Let's see what others think before deciding.
upvoted 0 times
...
Xochitl
2 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
2 months ago
I think the answer is A because the code creates an object of class B without any parameters.
upvoted 0 times
...
Cathrine
2 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
2 months ago
I disagree, I believe the correct answer is C. It prints: A no parametersB string parameter.
upvoted 0 times
...
Cathrine
2 months ago
I think the answer is A. It prints: A no parametersA no parametersB string parameter.
upvoted 0 times
...

Save Cancel