Which two are valid instantiations and initializations of a multi dimensional array?

Which two are valid instantiations and initializations of a multi dimensional array?

Which two are valid instantiations and initializations of a multi dimensional array?

A.
int [] [] array 2D = { { 0, 1, 2, 4} {5, 6}};

B.
int [] [] array2D = new int [2] [2];
array2D[0] [0] = 1;
array2D[0] [1] = 2;
array2D[1] [0] = 3;
array2D[1] [1] = 4;

C.
int [] [] [] array3D = {{0, 1}, {2, 3}, {4, 5}};

D.
int [] [] [] array3D = new int [2] [2] [2];
array3D [0] [0] = array;
array3D [0] [1] = array;
array3D [1] [0] = array;
array3D [0] [1] = array;

E.
int [] [] array2D = {0, 1};

Explanation:
In the Java programming language, a multidimensional array is simply an array
whose components are themselves arrays.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Jazz

Jazz

B,E – : In the Java programming language, a multidimensional array is simply an array
whose components are themselves arrays.

tom

tom

E is wrong? This is a one-dimentional assignment two a two-dimentional array.

antonello

antonello

A,B

ming

ming

there is no comma between {1,2,3,4} {5,6} in A. A is wrong. Only B is correct.

ming

ming

There is no comma(,) between {1,2,3,4} and {5,6} in A. The A is wrong.

Naira

Naira

Only B is correct: in D an array variable is used which is not initialized.