Java OCA OCP Practice Question 1078

Question

What will be the result of attempting to run the following program?

public class Main{ 
   public static void main (String args []){ 
      String [][][] arr  ={{  /*  w ww  .  j  av  a2 s  .c  o m*/
            { "a", "b" , "c"},  
            { "d", "e", null  }  
        }, {  
            {"AAA"}, null  },
            {{"BBB"}},
            {  { "z","p"},  {}  
        }}; 
      System.out.println (arr [0][1][2]); 
    } 
} 

Select 1 option

A. It will throw NullPointerBoundsException. 
B. It will throw ArrayIndexOutOfBoundsException. 
C. It will print null. 
D. It will run without any error but will print nothing. 
E. None of the above. 


Correct Option is  : C

Note

A. is wrong. There is no such exception.


arr [0][1][2] => [0] =  {  
      { "a", "b" , "c"},  
      { "d", "e", null  }  
}, [1] =  { "d", "e", null  } 

and [2] = null.

So it will print null.




PreviousNext

Related