C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 28)
28.
Which of the following functions are performed by a constructor?
Construct a new class
Construct a new object
Construct a new function
Initialize objects
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 1 of 2.

Kanak Agrawal said:   4 years ago
The constructor is used to initialize an object.
And a object is created using "new".
So, option D is correct.

Adeq said:   6 years ago
A constructor is a member function of a class that initializes objects of a class. In C++, Constructor is automatically called when an object(instance of class) is created.

So this is the first function that is automatically called after the creation of object.

Cool SAM said:   8 years ago
Give me the Proper definition of the constructor.

Vikram Ajabe said:   8 years ago
Constructor is used to the initialising state of the object. Constructor is invoked at the time of object creation.

Peter said:   10 years ago
Indeed, there should be option E/ saying both B and D are valid. + may be even F/ claiming all are correct, or A, B, C to provide some distraction for those who are unsure.

But the Q as it stands now is distracting those, who know, and answer D is not sufficient. Constructor initializes default values, but according to best practice methods, those are init (param) functions, that should initialize state of object to wanted values.

Niteen said:   10 years ago
@Vimalesh Valiya : That's correct both options are right.

Deepa t.s said:   1 decade ago
Constructor it is a special member function, called automatically during object creation.

Vimalesh valiya said:   1 decade ago
Constructor jobs are to do the following:

[B] Construct a new object.
[D] Initialize objects.

Both Option B and Option D are valid and correct.

Ranjan Kumar Mishra said:   1 decade ago
After declaration of object a default constructor internally call by compiler if we don't create any parameterized object and constructor which initializes the object.

Sachin Shinde said:   1 decade ago
Constructor initializes objects of class, if programmer(we) don't write default constructor then compiler will provide.


Post your comments here:

Your comments will be displayed after verification.