Java OCA OCP Practice Question 853

Question

Which is the first line to prevent this code from compiling and running without error?

char[][] myField = new char[3,3];                  // r1 
myField[1][3] = 'X';                               // r2 
myField[2][2] = 'X'; 
myField[3][1] = 'X'; 
System.out.println(myField.length + " in a row!"); // r3 
  • A. Line r1
  • B. Line r2
  • C. Line r3
  • D. None of the above


A.

Note

A multi-dimensional array is created with multiple sets of size parameters.

The first line should be char[] myField = new char[3][3];.

Therefore, Option A is the answer.




PreviousNext

Related