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 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
28 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
1 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
1 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
Martha
3 days ago
Yes, that's correct. It will print: Constructor from First
upvoted 0 times
...
Enola
14 days ago
I agree, it should print: Constructor from First
upvoted 0 times
...
Malcom
15 days ago
I think it prints: Constructor from First
upvoted 0 times
...
...
Wendell
1 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
Annamae
14 days ago
A) It prints: Constructorfrom First
upvoted 0 times
...
...
Avery
2 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
3 days ago
Yeah, I'm leaning towards B as well
upvoted 0 times
...
Cherilyn
9 days ago
I agree, I also think it will print: Constructor
upvoted 0 times
...
Elise
11 days ago
I think it will print: Constructor
upvoted 0 times
...
Xuan
11 days ago
User 3: So, B is the correct answer then.
upvoted 0 times
...
Stephaine
15 days ago
User 2: Yeah, I agree with that. The constructor is the only thing being called.
upvoted 0 times
...
Ellsworth
22 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
24 days ago
A) It prints: Constructorfrom First
upvoted 0 times
...
Kaitlyn
1 months ago
Then the Print() function is called, so it should print 'from First'
upvoted 0 times
...
Barabara
1 months ago
I agree, the constructor is called first so it should print 'Constructor'
upvoted 0 times
...
Antonio
2 months ago
I think it prints: Constructorfrom First
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