OCA Java SE 8 Mock Exam 2 - OCA Mock Question 40








Question

Which of the following are valid lines of code to define a multidimensional int array?

    a  int[][] array1 = {{1, 2, 3}, {}, {1, 1, 1, 1, 1}}; 
    b  int[][] array2 = new array() {{1, 1, 1}, {}, {1, 1,1, 1, 1}}; 
    c  int[][] array3 = {1, 2, 3}, {0}, {1, 1,1, 1, 1}; 
    d  int[][] array5 = new int[2][]; 

Answer



A, D





Note

B is incorrect. This line of code won't compile because new array() isn't valid code.

C is incorrect. To initialize a two-dimensional array, all of these values must be enclosed within another pair of curly braces.