Oracle 1Z0-808 Exam question no. 40

Q.- Given the code fragment: 

public static void main(String [] args) {
           int ans; 
           try  {
                 int num = 10; 
                 int div = 0; 
                 ans = num / div; 
           }
           catch (ArithmeticException ex)   {
                 ans = 0;                                                // line n1
           }  
           catch (Exception e)   {
                 System.out.println("Invalid calculation”);
          }
          System.out.println ("Answer = " +ans);       // line n2 
}

What is the result? 

A) Answer = 0 

B) Compilation fails at line n1 and line n2. 

C) Compilation fails only at line n1. 

D) Invalid calculation 

E) Compilation fails only at line n2.



⧪ please give your answer in a comment section.

Post a Comment

6 Comments