Java OCA OCP Practice Question 626

Question

The following program will print 'java.lang.ArithmeticException: / by zero'.

class Test{ //from   w  ww. jav a 2s.com
   public static void main (String [] args){ 
      int d = 0; 
      try{ 
         int i = 1 /  (d* doIt ()); 
       } catch  (Exception e){ 
         System .out.println (e); 
       } 
    } 
   public static int doIt () throws Exception{ 
       throw new Exception ("Forget It"); 
    } 
} 

Select 1 option

  • A. True
  • B. False


Correct Option is  : B

Note

It will print Forget It

because before the division can take place doIt () will throw an exception.




PreviousNext

Related