Passing Arrays to Methods
Which THREE statements are true about passing arrays to methods in Java?
Quick Answer
The correct answer is that passing null as an array argument is allowed at compile time, because Java treats arrays as objects, and null is a valid reference value for any object type, including arrays. This means a method declared with an array parameter, such as `void process(int[] arr)`, will compile without error when invoked with `null`, though it may throw a NullPointerException at runtime if the method tries to access elements without a null check. On the Oracle Java Foundations 1Z0-811 exam, this concept tests your understanding of reference types versus primitive types, and a common trap is assuming that passing null causes a compile-time error. Another key point is that varargs, written as `Type... param`, are syntactic sugar for an array parameter, so they also accept null and zero arguments. To remember this, think: "Arrays are objects, null is a valid object reference — compile accepts, runtime checks."
⚠ Common exam trap
It's easy for candidates to confuse pass-by-value for object references with pass-by-reference, leading them to incorrectly believe that reassigning the parameter (Option C) or modifying elements (Option A) behaves the same way, when in fact only element modifications are visible to the caller.
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
✓
Varargs parameters allow passing zero or more arguments of the specified type.
Varargs (variable-length arguments) in Java allow a method to accept zero or more arguments of a specified type, using the syntax `Type... param`. This is syntactic sugar for an array parameter, and the method body treats it as an array. This enables flexible method invocation without requiring the caller to explicitly create an array.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
If the method modifies elements of the array, the caller does not see the changes.
Why it's wrong here
Changes to elements are visible to the caller because they share the same array object.
- ✓
Varargs parameters allow passing zero or more arguments of the specified type.
Why this is correct
Varargs (T...) accept multiple arguments or an array.
- ✗
If the method assigns a new array to the parameter, the caller's variable is updated.
Why it's wrong here
Only the local reference is changed; caller's variable still points to original array.
- ✓
The method receives a reference to the array.
Why this is correct
Java passes the reference by value.
- ✓
Passing null as an array argument is allowed at compile time.
Why this is correct
Null can be passed to any array parameter; runtime behavior may cause NullPointerException.
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 →
Same concept, more angles
2 more ways this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which two statements about passing arrays to methods are correct? (Select two.)
hard- A.Passing an array is the same as passing each element individually.
- B.The method can change the size of the original array.
- ✓ C.Modifying the array elements inside the method affects the original array.
- D.If the method assigns a new array to the parameter, the original reference is updated outside the method.
- ✓ E.The array reference is passed by value.
Why C: In Java, arrays are objects, and when you pass an array to a method, you pass a copy of the reference to the array. This means the method can modify the contents of the array (e.g., change element values), and those changes are reflected in the original array because both the caller and the method refer to the same array object in heap memory.
Variation 2. Which TWO statements are true about passing arrays to methods in Java?
medium- A.The method can reassign the original array variable to a new array.
- ✓ B.The method can modify the elements of the array.
- C.The method must return the array to reflect any changes.
- ✓ D.The method receives a copy of the array reference.
- E.The method cannot determine the size of the array.
Why B: Java passes object references by value. When an array is passed to a method, the method receives a copy of the reference to the array object. This copy still points to the same array object in heap memory, so the method can modify the elements of the array through that reference. These modifications are visible to the caller because they affect the same underlying array object.
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.