Machine-translated by Google. Questions are authored in English.
Top

Constructors and Destructors Questions and Answers

1.

The copy constructor must receive its arguments by :

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: A

The copy constructor must receive its argument only by reference.

A copy constructor has the form X(const X& other). If the argument were passed by value, calling the copy constructor would require making a copy of the argument, which would call the copy constructor again, recursing without end. C++ therefore forbids a copy constructor that takes its own class by value.

Passing by address (a pointer) gives an ordinary constructor, not a copy constructor, so 'only by address', 'only by value' and 'either by value or by reference' are all wrong.

Please log in or register to report this question.

2.

Which one of the following ensures proper cleanup of objects of the type ?

(i) Destructor
(ii) Delete
(iii) Exception Handling
(iv) Garbage Collection

Exam Year(s)

MH SET - 2019, SET Exam - 2019,

Answer: A

The answer is (i) only, the destructor.

In C++, the destructor is the member function that the language calls automatically when an object goes out of scope or is deleted. It releases the object's resources, such as memory, files and locks, so it is what ensures proper cleanup for objects of the type.

delete is an operator that ends a dynamically allocated object's life by calling its destructor, so it relies on the destructor rather than defining the cleanup. Exception handling deals with error conditions, and garbage collection reclaims memory in some languages but runs at unpredictable times and does not provide deterministic cleanup.

Please log in or register to report this question.

3.

In C++, what is the main purpose of destructors ?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: B

The main purpose of a C++ destructor is that they are used for memory deallocation.

A destructor, named with a tilde (~ClassName), runs automatically when an object goes out of scope or is deleted. Its job is to release resources the object holds, typically freeing dynamically allocated memory and closing files.

Initialising an object is the constructor's job. Destructors destroy objects, not the class, and they cannot return a value.

Please log in or register to report this question.

4.

Which of the following is true about constructors in C++ ?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: B

The true statement is A constructor has the same name as the class.

A C++ constructor is a member function with the same name as its class, called automatically when an object is created, to initialise it.

Constructors have no return type and cannot return values. They need not have parameters (a default constructor has none). A constructor is normally called automatically when an object is created; whatever one makes of explicit calls such as ClassName(args), the defining property the key asks for is the shared name.

Please log in or register to report this question.

5.

Which method is called automatically when an object is destroyed in C++?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: A

The method called automatically when a C++ object is destroyed is the Destructor.

When an object goes out of scope, or is deleted with delete, its destructor (~ClassName) is called automatically to release resources.

The constructor runs at creation, not destruction. finalize() is a Java method once called by the garbage collector, and there is no automatic Cleanup() method in C++.

Please log in or register to report this question.

6.

In C++, what happens if a base class destructor is NOT declared virtual and a derived object is deleted via base pointer ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: D

The keyed answer is that only the base class destructor is called.

Deleting a derived object through a base pointer calls the destructor that the pointer's static type selects. If the base destructor is not virtual, there is no dynamic dispatch, so the call goes to the base class destructor and the derived class destructor is skipped, leaking whatever the derived part owned. The C++ standard formally makes this undefined behaviour, but in practice this is what happens, and it is why base classes meant for polymorphic use should have virtual destructors.

Both destructors run, derived first, only when the base destructor is virtual. The derived destructor never runs alone here, and the code compiles without error.

Please log in or register to report this question.

7.

In C++, which function has the same name as the class and is called automatically when an object is created ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The function is the constructor.

A C++ constructor has the same name as its class, has no return type, and is called automatically whenever an object of the class is created, to initialise its data members. A class may have several constructors with different parameters.

The destructor also takes the class name, but with a tilde (~ClassName), and it runs when an object is destroyed, not created. main is the program's entry point, and a virtual function is one that can be overridden in a derived class.

Please log in or register to report this question.

Answer: C

A class can have Multiple CONSTRUCTORS and one DESTRUCTOR.

Constructors can be overloaded: a class may have a default constructor, parameterised constructors and a copy constructor, distinguished by their parameter lists. A destructor takes no arguments and cannot be overloaded, so a class has exactly one.

'One constructor' understates what overloading allows, and any option with multiple destructors is impossible, because ~ClassName() has a single fixed signature.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Constructors and Destructors Questions and Answers || Constructors and Destructors MCQ Questions and Answers || Constructors and Destructors GK Questions and Answers || Constructors and Destructors GK MCQ Questions || Constructors and Destructors Multiple Choice Questions and Answers || Constructors and Destructors GK || GK on Constructors and Destructors || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming