1.

What is the main purpose of the constructor?(a) Begin the execution of class(b) Include the macros for the program(c) Establish the class invariant(d) Terminate the programI have been asked this question in an interview.The question is from Exceptions and Efficiency topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right ANSWER is (c) Establish the class invariant

The best I can explain: The purpose of a constructor is to establish the class invariant. To do that, it often NEEDS to acquire SYSTEM resources or in general PERFORM an operation that MAY fail.



Discussion

No Comment Found

Related InterviewSolutions