Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What can prevent a finally block from executing?

  1. An uncaught exception in the try block

  2. A return statement in the try block

  3. A call to System.exit()

  4. Nothing can prevent the finally block from executing

The correct answer is: A call to System.exit()

A call to System.exit() is an explicit way of terminating the entire Java program and therefore prevents any code, including the finally block, from executing after it. Options A and B may lead to the catch block being executed, but the finally block will still run. Option D is incorrect because the finally block will execute unless the program is terminated, which can be done through a call to System.exit().