If a class object is thrown with a throw statement, then a subsequent catch block has a usable match if the type of the catch argument is_________

[amp_mcq option1=”a parent class of the thrown class” option2=”a child class of the thrown class” option3=”either (a) or (b)” option4=”neither (a) nor (b)” correct=”option3″]

The correct answer is: C. either (a) or (b)

A catch block has a usable match if the type of the catch argument is a parent class of the thrown class or a child class of the thrown class.

For example, if a MyException object is thrown, then a catch (MyException e) block will match. A catch (Exception e) block will also match, because Exception is a parent class of MyException.

However, a catch (Object e) block will not match, because Object is not a parent class of MyException.

Exit mobile version