1Z0-811 Arrays and Methods Practice Question
A method is designed to compute the average of an array of test scores. What should the method return if the array is empty (length 0)?
⚠ Common exam trap
Oracle often tests the distinction between primitive and wrapper types; the trap here is that candidates may think returning null is acceptable for a double return type, but double is a primitive and cannot hold null.
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
✓
Return 0.0
The method should return 0.0 for an empty array to avoid division by zero and to provide a safe default value. In Java, an empty array has length 0, and computing the average would require dividing by zero, which throws an ArithmeticException. Returning 0.0 is a common convention for empty collections, as it allows the caller to handle the result gracefully without crashing.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Return 0.0
Why this is correct
Default value for empty average.
- ✗
Do not compile; requires a return of type double
Why it's wrong here
It will compile if a return is provided; returning 0.0 works.
- ✗
Throw a RuntimeException
Why it's wrong here
Not required; returning 0.0 is acceptable.
- ✗
Return null
Why it's wrong here
Return type is double, not Double; cannot return null.
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.