Java OCA OCP Practice Question 1745

Question

If a try, a catch, and a finally statement are used together but no exception is generated, which blocks are executed and in which order?

  • A. try
  • B. try, catch
  • C. try, catch, finally
  • D. try, finally


D.

Note

If no exception is thrown, then the catch block will not be executed.

The try block is always visited first, followed by the finally block, which is guaranteed to execute regardless of whether an exception is thrown.

For these reasons, Option D is the correct answer, with the statements in the correct order.




PreviousNext

Related