Given static int f() { try { return 1; } finally { System.out.print(“F”); } }, what does System.out.print(f()); print?
Correct answer C. F1
Explanation
The return value 1 is computed first, but the finally block must complete before the method actually returns to its caller. The argument f() is evaluated before the outer print runs, so F appears first and then 1. A finally block runs whether the try block completes normally, returns or throws an exception.
Answer checked How we write and check questions
Discussion