Question 60

In which case it is mandatory to provide a destructor in a class?

  1. AAlmost in every class
  2. BClass for which two or more than two objects will be created.
  3. CClass for which copy constructor is defined.
  4. DClass whose objects will be created dynamically.
Show answerHide answer

Correct answer: (D) Class whose objects will be created dynamically.

Explanation

A class whose objects are created dynamically, or that allocates memory with new, needs a destructor to free that memory. Otherwise the memory leaks.

From DSSSB TGT Computer Science Practice Set 1

This is question 60 of DSSSB TGT Computer Science Practice Set 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.