C++ Programming - OOPS Concepts - Discussion

Discussion :: OOPS Concepts - General Questions (Q.No.28)

28. 

Which of the following functions are performed by a constructor?

[A]. Construct a new class
[B]. Construct a new object
[C]. Construct a new function
[D]. Initialize objects

Answer: Option D

Explanation:

No answer description available for this question.

Xyz said: (Jul 8, 2012)  
Every Class should define it's own Constructor.

Tushar Bhimarao Dongare said: (Sep 27, 2012)  
Constructor it is a special member function it is used to initialize object of class.

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

Ranjan Kumar Mishra said: (Apr 24, 2014)  
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.

Vimalesh Valiya said: (Jul 31, 2014)  
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.

Deepa T.S said: (Sep 10, 2014)  
Constructor it is a special member function, called automatically during object creation.

Niteen said: (Sep 9, 2015)  
@Vimalesh Valiya : That's correct both options are right.

Peter said: (Jan 15, 2016)  
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.

Vikram Ajabe said: (Apr 24, 2017)  
Constructor is used to the initialising state of the object. Constructor is invoked at the time of object creation.

Cool Sam said: (Jun 17, 2017)  
Give me the Proper definition of the constructor.

Adeq said: (Oct 12, 2019)  
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.

Kanak Agrawal said: (Mar 17, 2021)  
The constructor is used to initialize an object.
And a object is created using "new".
So, option D is correct.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.