Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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
1 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
Rolf
5 days ago
That's what I was thinking too. C) it is.
upvoted 0 times
...
Daniela
11 days ago
Yeah, I agree. It should print: A no parameters B string parameter.
upvoted 0 times
...
Chaya
15 days ago
I think C) is the correct answer.
upvoted 0 times
...
...
Deangelo
1 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
1 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
Antonio
1 days ago
I agree, it's all about the order of constructor calls.
upvoted 0 times
...
...
Von
1 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
1 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
7 days ago
So the output should be A0 B1 C0.
upvoted 0 times
...
Rocco
11 days ago
Oh, I see. The constructors of the base classes are called in the order of inheritance.
upvoted 0 times
...
Daryl
1 months 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
3 months ago
I think the answer is A. It prints: A no parametersA no parametersB string parameter.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77