Which of the following are correct about constructors in C++?
A. They have the same name as the class.
B. They can return values.
C. They are called automatically when an object is created.
D. They can be overloaded.
E. They can be inherited.
Choose the correct answer from the options given below:
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. A, C & D only
Explanation
A constructor always has the same name as its class, so statement A is true. A constructor has no return type at all, not even void, so it can never return a value, making statement B false. A constructor is invoked automatically whenever an object of the class is created, so statement C is true. Constructors can be overloaded by giving the class multiple constructors with different parameter lists, so statement D is true. Constructors are not inherited by derived classes in C++ (a derived class must define its own constructors, though it may invoke a base-class constructor through the member-initializer list), so statement E is false. Hence only A, C and D are correct.More Programming Languages and Computer Graphics questions
- Arrange the following data types in non-decreasing order according to the length of their representation in C++. A. char B. int C. float D.…
- Which of the following would be the value of z for the C program code? x = 16; y = 4; z = x >> y;
- What will be the output of the following program? #include<stdio.h> int main() { int i; for (i = 0; i++<10; ) printf("%d", i++); return 0; }
- Match the LIST-I with LIST-II. LIST-I LIST-II A. Pivot point I. Reflection B. Fixed point II. Shear C. Mirror image III. Rotation D. Distor…
- The number of pixel columns divided by the number of scan lines that can be displayed by the system, is called
- The above figure shows a triangle at an original position (vertices labelled 2, 1, 3) to the left of the y-axis, and the same triangle, fil…