nerdexam
Oracle

1Z0-803 · Question #48

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

The correct answer is A. Option A D. Option D. This question assesses the candidate's understanding of the correct syntax for declaring, instantiating, and initializing multi-dimensional arrays, including both rectangular and jagged array forms.

Creating and Using Arrays

Question

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

Exhibit

1Z0-803 question #48 exhibit

Options

  • AOption A
  • BOption B
  • COption C
  • DOption D
  • EOption E

How the community answered

(25 responses)
  • A
    92% (23)
  • B
    4% (1)
  • C
    4% (1)

Why each option

This question assesses the candidate's understanding of the correct syntax for declaring, instantiating, and initializing multi-dimensional arrays, including both rectangular and jagged array forms.

AOption ACorrect

This option represents a valid way to instantiate a multi-dimensional array (often called a jagged array). For example, `int[][] arr = new int[3][];` correctly declares a 2D array with 3 rows, where each row can later be assigned an array of variable length.

BOption B

An invalid instantiation often involves specifying the second dimension without the first when using `new`, e.g., `int[][] arr = new int[][3];` which is syntactically incorrect.

COption C

An invalid declaration or instantiation could be incorrect placement of brackets like `int[3][4] arr;` or trying to combine dimension sizes with an initializer list in a way not supported by the language (e.g., `new int[2][3] { {1,2}, {3,4} }` in Java).

DOption DCorrect

This option represents a valid way to instantiate a rectangular multi-dimensional array by specifying the size for all dimensions. For example, `int[][] arr = new int[2][3];` correctly creates a 2D array with 2 rows and 3 columns.

EOption E

Invalid initializations can include assigning an initializer list directly to an inner array without `new int[]`, e.g., `arr[0] = {1,2};`, or incorrect syntax for creating anonymous arrays.

Concept tested: Multi-dimensional array instantiation and initialization syntax

Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html#multidimensional

Topics

#multi-dimensional arrays#array initialization#array declaration

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice