Difficulty: Easy
Correct Answer: A 3-D jagged array containing 2 two-dimensional jagged arrays.
Explanation:
Introduction / Context:
Jagged arrays are arrays of arrays. The number of bracket pairs indicates the depth, and the first allocation creates the outermost array only.
Given Data / Assumptions:
int[][][]
signals a three-level jagged structure.new int[2][][]
allocates the outermost array with length 2; inner arrays are uninitialized (null) until created.
Concept / Approach:
This declaration creates a 3-D jagged array, where each of the two outer slots will later hold a 2-D jagged array (int[][]
). It does not define rectangular dimensions; shapes of inner arrays can vary independently.
Step-by-Step Solution:
new int[2]
).Inner arrays: each element will be an int[][]
(2-D jagged) created later.
Verification / Alternative check:
Attempt to access intMyArr[0]
after allocation: it is null
until assigned a new int[][]
; this confirms jagged, not rectangular, behavior.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming new int[2][][]
initializes all levels; only the first level is allocated.
Final Answer:
A 3-D jagged array containing 2 two-dimensional jagged arrays.
Discussion & Comments