1.

Which among the following is true?(a) If catch block of base class is written first, it is compile time error(b) If catch block of base class is written first, it is run time error(c) If catch block of base class is written first, derived class catch block can’t be reached(d) If catch block of base class is written first, only derived class catch block is executedI got this question in an interview.This interesting question is from Catching Class Types in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (c) If catch block of base CLASS is WRITTEN FIRST, DERIVED class catch block can’t be reached

Best explanation: If the catch block of the base class is defined first and then the derived class catch block is given. The code becomes unreachable. HENCE the derived class catch block must be written first.



Discussion

No Comment Found

Related InterviewSolutions