Bird
0
0

Which statement best describes the behavior of the finally block in Java?

hard📝 Conceptual Q10 of 15
Java - Exception Handling

Which statement best describes the behavior of the finally block in Java?

Afinally block executes only if the try block completes without exceptions.
Bfinally block executes regardless of whether an exception is thrown or caught, unless the JVM exits.
Cfinally block executes only if the try block throws an exception.
Dfinally block executes only if there is a catch block present.
Step-by-Step Solution
Solution:
  1. Step 1: Understand finally block execution conditions

    finally block runs no matter what, except if JVM exits or thread is killed.
  2. Step 2: Evaluate options

    Options A, C, and D limit finally execution incorrectly; only B correctly states unconditional execution.
  3. Final Answer:

    finally block executes regardless of whether an exception is thrown or caught, unless the JVM exits. -> Option B
  4. Quick Check:

    finally runs always unless JVM exits [OK]
Quick Trick: finally runs always unless JVM exits abruptly [OK]
Common Mistakes:
  • Thinking finally runs only on exceptions
  • Assuming finally needs catch block
  • Believing finally skips on normal completion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes