Practice mode Java

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.