ProgrammingHardProduct-company placement · Java

What is printed?

What is printed?
try {
    System.out.print("T");
    System.exit(0);
} finally {
    System.out.print("F");
}
  1. A. T
  2. B. TF
  3. C. FT
  4. D. F

Correct answer: A. T

System.exit stops the JVM; the try block never completes, so the finally block is not run. (finally covers return, break and exceptions, not JVM termination.)

More OOP with C++ and Java questions

Exams that ask this topic