Which of the following correctly describes the behavior of the `finally` block in Java?

Java Associate Medium

Java Associate — Medium

Which of the following correctly describes the behavior of the `finally` block in Java?

Key points

  • The `finally` block is guaranteed to execute.
  • It is used for cleanup tasks like closing files or database connections.
  • Even if an exception occurs, the `finally` block will still run.

Ready to go further?

Related questions