1Z0-811 Arrays and Methods Practice Question
A developer writes a method that takes an int array and returns the sum of its elements. The method signature is: 'public static int sumArray(int[] arr)'. Which statement correctly calls this method?
⚠ Common exam trap
Oracle often tests the distinction between array initializer syntax (valid only in declarations) and anonymous array syntax (required when passing an array directly to a method), causing candidates to mistakenly use `[1,2,3]` or a single value instead of the proper `new int[]{...}` form.
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 result = sumArray(new int[]{1,2,3});
It uses the correct syntax for creating and passing an anonymous int array to the sumArray method. The expression `new int[]{1,2,3}` creates an int array object with the specified elements, which matches the method's parameter type `int[]`. The method then returns the sum, which is assigned to the int variable `result`.
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 result = sumArray(new int[]{1,2,3});
Why this is correct
This statement correctly invokes the `sumArray` method by providing an `int` array argument, precisely matching the `int[] arr` parameter defined in the method signature. The `new int[]{1,2,3}` syntax creates an anonymous integer array literal, which is then correctly passed to the static method. The method's `int` return value is subsequently assigned to the `int result` variable, ensuring type compatibility. This demonstrates the correct mechanism for passing an array argument to a static method.
- ✗
int result = sumArray(true);
Why it's wrong here
Passes a boolean, not an array.
- ✗
int result = sumArray([1,2,3]);
Why it's wrong here
Invalid syntax; use new int[]{...}.
- ✗
int result = sumArray(5);
Why it's wrong here
Passes an int, not an array.
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.