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
13 days 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
15 days 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
16 days 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
...
Wendell
23 days 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
...
Avery
1 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
Ellsworth
7 days ago
User 1: I think it prints: Constructor
upvoted 0 times
...
...
Carmen
2 months ago
I'm not sure, but I think it prints: Constructorfrom First
upvoted 0 times
...
Dominque
2 months ago
I believe it prints: Constructor
upvoted 0 times
...
Ashlyn
2 months ago
I think it prints: Constructorfrom First
upvoted 0 times
...
Omer
2 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
9 days ago
A) It prints: Constructorfrom First
upvoted 0 times
...
Kaitlyn
19 days ago
Then the Print() function is called, so it should print 'from First'
upvoted 0 times
...
Barabara
20 days ago
I agree, the constructor is called first so it should print 'Constructor'
upvoted 0 times
...
Antonio
1 months ago
I think it prints: Constructorfrom First
upvoted 0 times
...
...

Save Cancel