Constructors are used to
When a copy constructor may be called?
What is the output of following C++ program?
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(const Point &p) { x = p.x; y = p.y; }
int getX() { return x; }
int getY() { return y; }
};
int main()
{
Point p1;
Point p2 = p1;
cout << "x = " << p2.getX() << " y = " << p2.getY();
return 0;
}
C++ provides a special ………………… called the constructor, which enables an object to initialize itself when it is created.
A constructor has the same …………….. as that of class.
Constructors are normally used to …………….. and to allocate memory.
A constructor that accepts no parameters is called the …………….
Constructors cannot be inherited, through a derived class can call the ………………. constructor.
State whether the following statements about the constructor are True or False.
i) Constructors should always be declared in the private section.
ii) Constructors are invoked automatically when the objects are created.
The constructors that can take arguments are called ……………...
When an object is created and initialized at the same time, a ………………. gets called.
In C++, ……………………. creates objects even through it was not defined in the class.
…………….. constructor will not do anything and defined just to satisfy the compiler
The ………………… constructor can be called with either one argument or no arguments.
A ………………….. is used to declare and initialize an object from another object.