1Z0-811 Arrays and Methods Practice Question
What is the result of the following code? int[] arr = new int[3]; arr[3] = 5; System.out.println(arr[3]);
⚠ Common exam trap
Oracle often tests the distinction between compile-time errors and runtime exceptions, and the trap here is that candidates mistakenly think an invalid array index causes a compilation error, when in fact the compiler only checks syntax and type safety, not index bounds.
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
✓
Runtime exception
The code attempts to access index 3 of an array of length 3. Since Java arrays are zero-indexed, valid indices are 0, 1, and 2. Accessing index 3 throws an ArrayIndexOutOfBoundsException at runtime, so option A is correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Runtime exception
Why this is correct
ArrayIndexOutOfBoundsException is thrown at runtime.
- ✗
0
Why it's wrong here
The assignment fails, so no output; exception is thrown.
- ✗
5
Why it's wrong here
The array does not have index 3; an exception is thrown before assignment.
- ✗
Compilation error
Why it's wrong here
The code compiles; the error occurs at runtime.
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.