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

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

Want to excel in Java? Test your knowledge with our ultimate quiz based on 'Thinking in Java'. Engage with multiple-choice questions and in-depth explanations. Boost your understanding and prepare for your exam with confidence.

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.


When does the finally block get executed?

  1. Immediately after the try block, regardless of exceptions

  2. Only if no exceptions were thrown in the try block

  3. After catch blocks, regardless of exceptions being thrown or caught

  4. It doesn't execute if the application exits within the try block

The correct answer is: After catch blocks, regardless of exceptions being thrown or caught

The finally block will always get executed, regardless of exceptions being thrown or caught in the try block. Option A and B are both incorrect because the finally block will still execute, even if exceptions are thrown in the try block. Option D is also incorrect because the finally block will still execute before the application exits within the try block. The finally block is often used for code that needs to be executed, such as closing open resources, regardless of whether an exception occurs.