1Z0-811 Arrays and Methods Practice Question
Which two of the following are valid ways to declare and initialize an array of integers? (Select two.)
⚠ Common exam trap
It's easy for candidates to confuse the declaration syntax (where size is not allowed) with the instantiation syntax (where size can be specified), leading them to pick Option A or C.
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[5];
It declares an integer array with a size of 5 using valid syntax, and the array is initialized with default values (0 for each element). In Java, `new int[5]` allocates memory for 5 integers and sets them to 0, which is a valid initialization.
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[5]{1, 2, 3, 4, 5};
Why it's wrong here
You cannot specify both the size and the initializer; the size is inferred from the initializer.
- ✓
int[] arr = new int[5];
Why this is correct
Creates an array of size 5 with default values (0).
- ✗
int[5] arr;
Why it's wrong here
Invalid syntax; the size cannot be specified on the left side of the variable.
- ✓
int arr[] = new int[]{1, 2};
Why this is correct
Creates an array with two elements. The syntax int arr[] is equivalent to int[] arr.
- ✗
int arr = new int[5];
Why it's wrong here
The variable type must be int[] (array), not int.
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.