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 *


Abed Abu Alhalawa

Abed Abu Alhalawa

B , D

Antonello

Antonello

‘D’ answer seems odd!
What is the meaning of the word “array”?
‘A’ seems correct except for a space between “array” and “2D” is that a mystyping?
Please let me know what you think.

ming

ming

declare int[] array = {1,2};

James

James

Answer is A, B

James

James

Answer A was mistyped and should have been written as:

int [] [] array2D = {{0, 1, 2, 4}, {5, 6}};