Difficulty: Easy
Correct Answer: BDE
Explanation:
Introduction / Context:This problem checks exception selection among multiple catch blocks and confirms that finally always executes, followed by normal execution after the try-catch-finally completes.
Given Data / Assumptions:
Concept / Approach:Catch selection goes top-down: the first compatible catch handles the exception. RuntimeException matches the first catch, so the second catch is skipped. finally executes regardless, then the flow continues.
Step-by-Step Solution:
badMethod throws RuntimeException.catch (RuntimeException) executes and prints "B".finally executes and prints "D".After try-catch-finally, "E" prints.Verification / Alternative check:Swap the order of catch blocks (Exception first) to see a compilation error due to unreachable catch for RuntimeException.
Why Other Options Are Wrong:
Common Pitfalls:Expecting the code after throw to run (the "A" is never reached). Misunderstanding that only one matching catch runs.
Final Answer:BDE
Discussion & Comments