1.

When is it advised to have user defined destructor?(a) When class contains some pointer to memory allocated in class(b) When a class contains static variables(c) When a class contains static functions(d) When a class is inheriting another class onlyThis question was addressed to me during an online exam.Origin of the question is Destructors topic in division Constructors and Destructors of Object Oriented Programming

Answer»

The correct answer is (a) When class contains some pointer to MEMORY allocated in class

Explanation: This is always advised to have user defined destructor when pointers are involved in class. This is usually done to ensure that the memory, that was allocated dynamically, GETS FREE after use and doesn’t cause memory LEAK.



Discussion

No Comment Found

Related InterviewSolutions