Java OCA OCP Practice Question 715

Question

What will the following program print?

class Test{ //from  w  ww.ja va 2s. c o  m
   public static void main (String [] args){ 
      int i = 4; 
      int myArray [][][] = new int [i][i = 3][i]; 
      System.out.println( 
         myArray.length + ", " + 
         myArray[0].length+", "+ 
         myArray[0][0].length); 
    } 
} 

Select 1 option

  • A. It will not compile.
  • B. 3, 4, 3
  • C. 3, 3, 3
  • D. 4, 3, 4
  • E. 4, 3, 3


Correct Option is  : E

Note

In an array creation expression, there may be one or more dimension expressions, each within brackets.

Each dimension expression is fully evaluated before any part of any dimension expression to its right.

The first dimension is calculated as 4 before the second dimension expression sets 'i' to 3.

If evaluation of a dimension expression completes abruptly, no part of any dimension expression to its right will appear to have been evaluated.




PreviousNext

Related