ProgrammingVery hardProduct company OA

What is printed?

What is printed?
for (int i = 0; i < 3; i++) {
    try {
        if (i == 1) continue;
        System.out.print(i);
    } finally {
        System.out.print("f");
    }
}
  1. A. 0ff2f
  2. B. 0f1f2f
  3. C. 012f
  4. D. 0f f2f (continue skips finally)

Correct answer: A. 0ff2f

i=0: prints 0, finally prints f -> "0f". i=1: continue skips the print of i but finally still runs before the loop continues -> "f". i=2: prints 2, finally prints f -> "2f". Concatenated: 0f + f + 2f = "0ff2f".

More OOP with C++ and Java questions

Exams that ask this topic