C++ Programming - OOPS Concepts - Discussion

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

17. 

Which of the following statement is correct?

[A]. A constructor is called at the time of declaration of an object.
[B]. A constructor is called at the time of use of an object.
[C]. A constructor is called at the time of declaration of a class.
[D]. A constructor is called at the time of use of a class.

Answer: Option A

Explanation:

No answer description available for this question.

Priyanka P said: (Jun 12, 2012)  
According to me, constructor is a special function which can be invoke when object is created.

Biraj said: (Sep 7, 2012)  
Option A and D are same and both are wrong.
Constructor is called at time of object creation :-)

Sri said: (Sep 28, 2012)  
When we are declare or creating the objects then the constructor is automatically invoked.

Shadab said: (Oct 8, 2012)  
According to me, When we are create a object then automatically create default Constructor.

Simran said: (Oct 17, 2012)  
Constructor is automatically called when we create the object.

Baru said: (Dec 20, 2012)  
Constructor having same class name that's why we are call the constructor at the time of object creation.

Object creation is:.

Classname refernce variable=new classname () ;.

In this constructor name n classname is also same that's why we are call the constructor at the time of object creation.

Pradeep said: (Jun 28, 2013)  
Because an constructor is called right when the object is created for a class.

Farhana said: (Jul 2, 2013)  
Constructor is a special member function of a class which is called/invoked when the object is created. It has the same name as that of a class.

Ashish Bardiya said: (Jul 3, 2013)  
Constructor is call when an object is created or initialize. When we not write a code for constructor then compiler automatically added default constructor.

Narmadhasrinivasan said: (Jul 15, 2013)  
Can you tell me whats the use of constructor?

Suvi said: (Aug 31, 2013)  
I think there one is the correct answer because in C++ declaring a object means its creation. :).

Vikrant Siwach said: (Oct 4, 2013)  
A constructor is always called when an object is initialized, not declared and certainly not "used".

Payal Y. Makan said: (Oct 27, 2013)  
A constructor is called whenever an object is created and declaration is nothing but creation of an object.

Divya said: (Feb 17, 2014)  
While creating an object, memory is allocated to that object when its constructor is invoked, it invokes only once during declaration of object, if you have not defined any constructor inside class then default constructor is invoked.

Ruthrakarthik said: (Apr 17, 2014)  
I think constructor will be called when object initialized.

Shashikala.R said: (May 20, 2014)  
How we can use copy constructors in real world problems?

Poonam said: (Oct 29, 2014)  
Constructor is called as soon as the object is invoked.

Shrikant said: (Nov 21, 2014)  
Because object needs to construct class elements and create real world object.

Bala Manikandan said: (Nov 24, 2014)  
A constructor is called at the time of initialization of an object and not at declaration.

Naveen Singh said: (Jun 19, 2015)  
If constructor is not define in class, then it will be provided by JVM automatically.

Sathriyan said: (Aug 28, 2015)  
When object is created automatically constructor is declared.

Ankush said: (Sep 5, 2015)  
Here is an example you can understand clearly :).

#include <iostream>

using namespace std;

class Line
{
public:
void setLength( double len );
double getLength( void );
Line(); // This is the constructor

private:
double length;
};

// Member functions definitions including constructor
Line::Line(void)
{
cout << "Object is being created" << endl;
}

void Line::setLength( double len )
{
length = len;
}

double Line::getLength( void )
{
return length;
}
// Main function for the program
int main( )
{
Line line;

// set line length
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;

return 0;
}

Yukthi said: (Mar 7, 2016)  
By default a constructor is immediately called as soon as an object is created.

Sanjay Nannaware said: (Sep 9, 2016)  
The constructor is a special member function of a class which is called/invoked when the object is created. It has the same name as that of a class.

Nino said: (Sep 28, 2017)  
A constructor is called at the time of declaration of an object.

class A {};
class C /* declaration of a class */
{
A a_; /* declaration of an object (but not definition) of type A */
};

will call the constructor of A?

Vedi G said: (Dec 7, 2019)  
constructor is called at the time of object creation.

#include<iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"constructor"<<endl;
}
}
int main()
{
A b1;
}

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.