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_________

a parent class of the thrown class
a child class of the thrown class
either (a) or (b)
neither (a) nor (b)

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