Multiple choice technology programming languages

Given: 31. // some code here 32. try { 33. // some code here 34. } catch (SomeException se) { 35. // some code here 36. } finally { 37. // some code here 38. } Under which three circumstances will the code on line 37 be executed? (Choose three.)

  1. The instance gets garbage collected.

  2. The code on line 33 throws an exception.

  3. . The code on line 35 throws an exception

  4. The code on line 31 throws an exception

  5. The code on line 33 executes successfully

Reveal answer Fill a bubble to check yourself
B,C,E Correct answer
Explanation

The finally block executes in three scenarios: B) when an exception is thrown in the try block, C) when an exception is thrown in the catch block, and E) when the try block completes successfully. Option A is false - garbage collection doesn't trigger finally. Option D is false - code before the try block (line 31) doesn't affect whether this try-catch-finally executes its finally. The finally block ALWAYS executes unless the JVM exits or there's a catastrophic failure.