1Z0-811 Java Basics and Syntax Practice Question
Given int[] arr = {1,2,3}; which correctly creates a new array with length 5 and copies the contents of arr?
⚠ Common exam trap
Candidates often confuse reference assignment (`=`) with array copying, or they misremember the exact method name (`Arrays.copy` vs `Arrays.copyOf`), leading them to pick options that either fail to copy or do not compile.
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[] newArr = Arrays.copyOf(arr, 5);
`Arrays.copyOf(int[] original, int newLength)` creates a new array of the specified length (5) and copies the elements from the original array into it, padding with default values (0 for int) for any extra positions. This method is specifically designed for this task, ensuring the original array remains unchanged.
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[] newArr = new int[5]; newArr = arr;
Why it's wrong here
Assignment makes newArr refer to arr, not a copy.
- ✗
int[] newArr = arr.clone(); newArr.length = 5;
Why it's wrong here
clone() creates an exact copy; cannot change length afterward.
- ✗
int[] newArr = Arrays.copy(arr, 5);
Why it's wrong here
Correct method is copyOf, not copy.
- ✓
int[] newArr = Arrays.copyOf(arr, 5);
Why this is correct
Arrays.copyOf creates a new array with specified length and copies elements.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.