Skip to main content

Constructors and Destructors

1).What is a constructor in C++?

1) A special member function used to initialize objects
2) A function used to destroy objects
3) A function with a return type
4) None of the above

2).Which of the following is true about constructors?

1) They have the same name as the class
2) They have a return type
3) They cannot be overloaded
4) None of the above

3).What is a destructor in C++?

1) A special member function used to destroy objects
2) A function used to initialize objects
3) A function with a return type
4) None of the above

4).How many destructors can a class have?

1) Only one
2) Multiple
3) None
4) None of the above

5).Which of the following is true about destructors?

1) They have the same name as the class but with a ~ prefix
2) They can be overloaded
3) They can have parameters
4) None of the above

6).What happens if a class does not have a constructor?

1) A default constructor is automatically provided
2) The program will not compile
3) Objects cannot be created
4) None of the above

7).Which of the following is a valid constructor declaration?

1) ClassName();
2) ClassName(void);
3) Both A and B
4) None of the above

8).Can a constructor call another constructor in the same class?

1) Yes, using constructor delegation
2) No
3) Only in derived classes
4) None of the above

9).What is the purpose of a copy constructor?

1) To create a new object as a copy of an existing object
2) To destroy an object
3) To handle memory allocation
4) None of the above

10).When is a destructor automatically invoked?

1) When an object goes out of scope
2) When a new object is created
3) When a constructor is called
4) None of the above