Difficulty: Easy
Correct Answer: Ex0 caught
Explanation:
Introduction / Context:
This validates understanding of exception inheritance and matching. A catch for a superclass type can handle exceptions of its subclass.
Given Data / Assumptions:
Concept / Approach:
Java chooses the first catch whose parameter type is assignable from the thrown exception type. Since Exc0 is a superclass of Exc1, the first catch matches.
Step-by-Step Solution:
Verification / Alternative check:
Swap the two catch blocks and observe that "exception caught" would execute instead because Exception would match first.
Why Other Options Are Wrong:
No compilation errors exist at the stated lines; the subclass relationship is valid. The second catch does not run because the first one already handled the exception.
Common Pitfalls:
Expecting a more general catch to run after a specific one; only the first matching catch executes.
Final Answer:
Ex0 caught
Discussion & Comments