Constructors
Question 1 |
Which of the following is NOT a type of constructor
Copy constructor | |
Friend constructor | |
Default constructor | |
Parameterized constructor |
Question 1 Explanation:
Parameterized constructors: Constructors that can take at least one argument are termed as parameterized constructors. When an object is declared in a parameterized constructor, the initial values have to be passed as arguments to the constructor function.
Default constructors: If the programmer does not supply a constructor for an instantiable class, Java/C++ compiler inserts a default constructor into your code on your behalf. This constructor is known as default constructor.
Copy Constructor: Copy constructors define the actions performed by the compiler when copying class objects. A Copy constructor has one formal parameter that is the type of the class (the parameter may be a reference to an object). It is used to create a copy of an existing object of the same class. Even though both classes are the same, it counts as a conversion constructor.
Default constructors: If the programmer does not supply a constructor for an instantiable class, Java/C++ compiler inserts a default constructor into your code on your behalf. This constructor is known as default constructor.
Copy Constructor: Copy constructors define the actions performed by the compiler when copying class objects. A Copy constructor has one formal parameter that is the type of the class (the parameter may be a reference to an object). It is used to create a copy of an existing object of the same class. Even though both classes are the same, it counts as a conversion constructor.