1Z0-811 Two-dimensional array declaration Practice Question
Which THREE are valid ways to declare and initialize a two-dimensional int array in Java?
⚠ Common exam trap
Oracle often tests the distinction between valid array initialization syntax and common invalid combinations, such as mixing `new` with an array initializer or omitting the first dimension size without an initializer, which trips up candidates who confuse C-style or other language syntax with Java's rules.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
int[][] arr = new int[2][2];
`int[][] arr = new int[2][2];` uses the standard syntax for declaring and initializing a two-dimensional int array in Java, where both dimensions are specified at creation time, and all elements default to 0. The first option (null key) is correct because `int[][] arr = {{1,2},{3,4}};` uses an array initializer to declare and initialize the array with specific values in a single statement, which is valid for local variables or fields. Option B is also correct because `int[][] arr = new int[2][4];` declares and initializes a two-dimensional array with dimensions 2 and 4, which is a valid syntax; both dimensions must be positive integers.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
int[][] arr = new int[2][2];
Why this is correct
Correct. This creates a 2x2 int array with all elements defaulting to 0.
- ✓
int[][] arr = new int[2][4];
Why this is correct
Correct. This creates a 2x4 int array, a valid declaration and initialization.
- ✗
int[][] arr = new int[][2];
Why it's wrong here
Invalid because the first dimension must be specified when using `new` without an initializer.
- ✗
int[][] arr = new int[2][2]{{1,2},{3,4}};
Why it's wrong here
Invalid because `new` and an array initializer cannot be combined in the same statement.
- ✗
int[][] arr = new int[2][];
Why it's wrong here
Invalid for the purpose of this question because `new int[2][]` creates a jagged array where the second dimension is not specified, so the rows are null; it is not considered fully initialized as a rectangular array.
- ✓
int[][] arr = {{1,2},{3,4}};
Why this is correct
Valid initialization with values.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.