ProgrammingModerateAccenture · Cognizant GenC

What is printed?

What is printed?
static int f() {
    try { return 1; }
    finally { System.out.print("F"); }
}
public static void main(String[] a) { System.out.print(f()); }
  1. A. 1F
  2. B. 1
  3. C. F1
  4. D. F

Correct answer: C. F1

The finally block runs before the method actually returns, so F is printed first and then the returned value 1 is printed.

More OOP with C++ and Java questions

Exams that ask this topic