Multiple choice technology

What will be the output of the program? try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println("Exception"); } catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); } System.out.println("finished");

  1. Compilation fails.

  2. finished

  3. Exception

  4. D.Arithmetic Exception

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

In Java exception handling, more specific catch blocks must come before more general ones. ArithmeticException is a subclass of Exception. The code catches the general Exception first, making the ArithmeticException block unreachable; compilation fails. If the order were reversed, the program would catch ArithmeticException, then print 'finished' after the catch block.