OCA Java SE 8 Exception - OCA Mock Question Exception 11








Question

What is the output of the following snippet, assuming a and b are both 0?

     1:     int a = 0;
     2      int b = 0;
     3:     try { 
     4:       return a / b; 
     5:     } catch (RuntimeException e) { 
     6:       return -1; 
     7:     } catch (ArithmeticException e) { 
     8:       return 0; 
     9:     } finally { 
     10:      System.out.print("done"); 
     11:    }  
  1. -1
  2. 0
  3. done-1
  4. done0
  5. The code does not compile.
  6. An uncaught exception is thrown.




Answer



E.

Note

Because ArithmeticException is a child class of RuntimeException, the catch block on line 7 is unreachable.