1Z0-809 · Question #68
Which two statements are true for a two-dimensional array of primitive data type?
The correct answer is A. It cannot contain elements of different types. Option A is correct because a two-dimensional array of a primitive type (e.g., int[][]) is declared with a fixed type - every element across all dimensions must be that same primitive type. Java's type system enforces this at compile time; you cannot mix int and double, for…
Question
Options
- AIt cannot contain elements of different types.
- BThe length of each dimension must be the same.
- CAt the declaration time, the number of elements of the array in each dimension must be specified.
- DAll methods of the class object may be invoked on the two-dimensional array.
How the community answered
(38 responses)- A79% (30)
- B13% (5)
- C3% (1)
- D5% (2)
Explanation
Option A is correct because a two-dimensional array of a primitive type (e.g., int[][]) is declared with a fixed type - every element across all dimensions must be that same primitive type. Java's type system enforces this at compile time; you cannot mix int and double, for example, in the same array.
Why the distractors are wrong:
- B is false because Java supports jagged arrays - each row can have a different length (e.g.,
int[3][]where row 0 has 2 elements and row 1 has 5). - C is false because you only need to specify the first dimension at allocation time; inner dimensions can be left unspecified and set later (e.g.,
new int[3][]is valid). - D is a subtle trap: a 2D array is an Object in Java and does inherit
Objectmethods (liketoString(),equals()), so this statement is actually true - meaning the intended correct answers are likely A and D, and the provided answer key may be incomplete.
Memory tip: Think of a primitive 2D array like a typed spreadsheet - every cell must hold the same type (A), but rows can have different widths (not B), and you don't have to fill in every column count upfront (not C).
Community Discussion
No community discussion yet for this question.