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 8 Question 35 Discussion

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

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

#include

using namespace std;

class First

{

public:

First() { cout << "Constructor";}

void Print(){ cout<<"from First";}

};

int main()

{

First FirstObject;

FirstObject.Print();

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Bulah
3 months ago
Wow, this is a real brain-teaser, isn't it? I mean, who could have possibly predicted that creating an object and calling a function on it would do something? Truly, the mysteries of the universe are unfurling before us.
upvoted 0 times
...
Eliz
3 months ago
I don't know, man. Maybe the code is secretly a recipe for a really fancy omelette or something. I mean, 'Constructor' and 'First' could be the ingredients, right? Hmm, maybe I should just stick to multiple-choice questions about cats instead.
upvoted 0 times
...
Mireya
3 months ago
Alright, let's think this through. The code is creating an object of the First class, and then calling the Print() function on that object. Sounds pretty straightforward to me. I'm going with A, 'Constructor from First'.
upvoted 0 times
Micaela
2 months ago
Great, we all agree on the output: Constructor from First
upvoted 0 times
...
Martha
2 months ago
Yes, that's correct. It will print: Constructor from First
upvoted 0 times
...
Enola
2 months ago
I agree, it should print: Constructor from First
upvoted 0 times
...
Malcom
3 months ago
I think it prints: Constructor from First
upvoted 0 times
...
...
Wendell
3 months ago
This is a classic case of 'what the code says versus what the code does'. The correct answer is C, my dudes. The Print() function is being called on the FirstObject, so it should just print 'from First'.
upvoted 0 times
Whitley
2 months ago
C) It prints: from First
upvoted 0 times
...
Arlette
2 months ago
B) It prints: Constructor
upvoted 0 times
...
Annamae
2 months ago
A) It prints: Constructorfrom First
upvoted 0 times
...
...
Avery
4 months ago
Woah, hold on a second. What if the constructor is the only thing that gets called? I mean, it's not like the Print() function is being called on a specific object or anything. I think I'm gonna go with B just to be safe.
upvoted 0 times
Ozell
2 months ago
Yeah, I'm leaning towards B as well
upvoted 0 times
...
Cherilyn
2 months ago
I agree, I also think it will print: Constructor
upvoted 0 times
...
Elise
2 months ago
I think it will print: Constructor
upvoted 0 times
...
Xuan
2 months ago
User 3: So, B is the correct answer then.
upvoted 0 times
...
Stephaine
3 months ago
User 2: Yeah, I agree with that. The constructor is the only thing being called.
upvoted 0 times
...
Ellsworth
3 months ago
User 1: I think it prints: Constructor
upvoted 0 times
...
...
Carmen
4 months ago
I'm not sure, but I think it prints: Constructorfrom First
upvoted 0 times
...
Dominque
4 months ago
I believe it prints: Constructor
upvoted 0 times
...
Ashlyn
4 months ago
I think it prints: Constructorfrom First
upvoted 0 times
...
Omer
4 months ago
Hmm, this looks like a tricky one. Let's see, the constructor is called, so it must print 'Constructor'. And then the Print() function is called, so it should print 'from First' as well. I'll go with A, it's gotta be the right answer.
upvoted 0 times
Val
3 months ago
A) It prints: Constructorfrom First
upvoted 0 times
...
Kaitlyn
3 months ago
Then the Print() function is called, so it should print 'from First'
upvoted 0 times
...
Barabara
3 months ago
I agree, the constructor is called first so it should print 'Constructor'
upvoted 0 times
...
Antonio
4 months ago
I think it prints: Constructorfrom First
upvoted 0 times
...
...

Save Cancel