Courseiva
Question 498 of 481
Arrays and MethodshardMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

A developer is working on a Java program that processes sensor data. The data is stored in a 2D array 'double[][] readings', where each row represents a sensor and each column a time interval. The method 'public static double[] averagePerSensor(double[][] data)' should compute the average reading for each sensor (row) and return a 1D array of averages. The developer writes the following implementation: 'double[] result = new double[data.length]; for (int i = 0; i < data.length; i++) { double sum = 0; for (int j = 0; j < data[i].length; j++) { sum += data[i][j]; } result[i] = sum / data[i].length; } return result;'. However, the program sometimes throws a NullPointerException. What is the most likely cause?

⚠ Common exam trap

Oracle often tests the distinction between a null row and a row with zero columns, where candidates mistakenly think a zero-length row causes the exception, but only a null reference triggers a NullPointerException when accessing array length or elements.

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

One or more rows in the 2D array are null.

The NullPointerException occurs because the code attempts to access `data[i].length` when `data[i]` is null. In Java, a 2D array is an array of arrays, and any row can be null. The code does not check for null rows before iterating over the columns, so if a row is null, accessing `data[i][j]` or `data[i].length` throws a NullPointerException. Option C correctly identifies this as the most likely cause.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The method returns a double[] but should return double[][].

    Why it's wrong here

    Return type is correct.

  • The rows have different numbers of columns.

    Why it's wrong here

    That is handled correctly by the inner loop.

  • One or more rows in the 2D array are null.

    Why this is correct

    Accessing length on null row causes NPE.

  • The outer loop uses data[i].length instead of data.length.

    Why it's wrong here

    Uses data.length correctly.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.