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 *


BT

BT

I believe B and E are the correct answers.

sully

sully

E starts of with 2 [] that means a 2D array
but on right side of equals {0,1} is only a single array.
Multidimensional is an array or arrays.

B & D are correct i believe

LaBarge

LaBarge

D only works only if you are assuming that the word ‘array’ on the right of the assignment operator is a variable already declared in another part of the code, and it refers to an Array of integers.

vij

vij

A abd B are correct

vij

vij

A and B are correct