Java OCA OCP Practice Question 782

Question

The following class will not throw a NullPointerException when compiled and run.

public class Main{ 
   public static void main (String [] args) throws Exception{ 
      int [] a = null; 
      int i = a  [getInt()]; 
    } 
   public static int getInt() throws Exception{ 
      throw new Exception ("Some Exception"); 
    } 
} 

Select 1 option

  • A. True
  • B. False


Correct Option is  : A

Note

m1() is called first, which throws Exception and so 'a' is never accessed and NullPointerException is never thrown.




PreviousNext

Related