1.

Which is the necessary condition to define the base and derived class catch blocks?(a) Base class catch should be defined first(b) Derived class catch should be defined first(c) Catch block for both the classes must not be defined(d) Catch block must be defined inside main functionThe question was posed to me in final exam.The above asked question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (b) Derived CLASS catch should be defined first

Explanation: The derived class catch BLOCKS must be defined prior to the base class catch BLOCK. This is to ensure that all the catch boxes are reachable. If not done, the code might become unreachable which in TURN makes the program prone to errors.



Discussion

No Comment Found

Related InterviewSolutions