Difficulty: Easy
Correct Answer: Hello world Finally executing
Explanation:
Introduction / Context:
Java allows a try block with a finally block even without any catch clauses. The finally block guarantees cleanup or final actions after the try completes, whether or not an exception occurs.
Given Data / Assumptions:
Concept / Approach:
When no exception is thrown, control flows from try to finally, then exits the method. Both outputs are printed in sequence.
Step-by-Step Solution:
Verification / Alternative check:
Add an exception inside try: the finally will still run before the program terminates or a catch (if present) runs.
Why Other Options Are Wrong:
Options claiming compilation failure are incorrect; Java permits try-finally without catch. Output is not only "Hello world." because finally adds more text.
Common Pitfalls:
Assuming a catch is mandatory with try; it is not if finally is present.
Final Answer:
Hello world Finally executing
Discussion & Comments