InterviewSolution
Saved Bookmarks
| 1. |
What are the various types of constructors in C++? |
|
Answer» The most common classification of constructors includes: Default constructor: The default constructor is the constructor which doesn’t take any ARGUMENT. It has no parameters. class ABC{ int x; ABC() { x = 0; }}Parameterized constructor: The constructors that take some arguments are known as parameterized constructors. class ABC{ int x; ABC(int y) { x = y; }}Copy constructor: A copy constructor is a member function that INITIALIZES an object USING another object of the same class. class ABC{ int x; ABC(int y) { x = y; } // Copy constructor ABC(ABC abc) { x = abc.x; }} |
|