1Z0-811 Arrays and Methods Practice Question
A method that calculates the average of an array of doubles is defined as:
public static double average(double[] values) {double sum = 0;
for (double v : values) sum += v;
return sum / values.length;
}Which call is valid?
⚠ Common exam trap
Oracle often tests the difference between array initializer syntax and anonymous array creation, trapping candidates who think `{1.0, 2.0, 3.0}` can be used as a method argument without the `new double[]` prefix.
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
✓
double avg = average(new double[]{1.0, 2.0, 3.0});
The method `average(double[] values)` expects a single argument of type `double[]`. The expression `new double[]{1.0, 2.0, 3.0}` creates an anonymous array object that matches the parameter type exactly, so the call compiles and runs correctly.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
double avg = average(1.0, 2.0);
Why it's wrong here
This passes two doubles, not an array, so it does not match the parameter type.
- ✓
double avg = average(new double[]{1.0, 2.0, 3.0});
Why this is correct
This creates a double array and passes it to the method.
- ✗
double avg = average(1.0, 2.0, 3.0);
Why it's wrong here
This syntax is only valid with varargs; the method expects an array, not a list of arguments.
- ✗
double avg = average({1.0, 2.0, 3.0});
Why it's wrong here
Anonymous array initializer syntax like {...} is only allowed in declaration statements, not as an argument.
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.