Multiple choice technology programming languages

Given: 33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(”a”); 37. } catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34?

  1. c

  2. a

  3. ab

  4. ac

  5. bc

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

NullPointerException is caught by the first catch block (more specific), printing a. The finally block always executes regardless of whether an exception was caught, printing c. The second catch block for RuntimeException is skipped because the exception was already caught by the more specific handler. Result is ac.