Courseiva
Arrays and MethodshardMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

A method is declared as: public static int[] generateSequence(int n) { ... }. Which return statement is valid inside this method?

⚠ Common exam trap

Oracle often tests the distinction between primitive types and array types, trapping candidates who think returning a single `int` or a literal `0` is acceptable because they overlook the `[]` in the return type.

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 new int[n];

The method's return type is `int[]`, meaning it must return a reference to an integer array. Option B, `return new int[n];`, creates an array of length `n` and returns it, which is valid. Option D, `return new int[0];`, also creates an integer array (of length 0) and returns it, which is syntactically valid as well. Options A and C are invalid because they return primitive `int` values, not `int[]` references. Therefore, both B and D are correct return statements.

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 result; where result is an int variable

    Why it's wrong here

    Returns an `int` variable, which is a primitive, not an `int[]` array. This causes a compile-time error because the return type is `int[]`.

  • return new int[n];

    Why this is correct

    Creates an integer array of length `n` and returns it. This is both syntactically and semantically valid for the method `generateSequence`.

  • return 0;

    Why it's wrong here

    Returns an `int` literal `0`, which is a primitive, not an array. This causes a compile-time error.

  • return new int[0];

    Why this is correct

    Creates an integer array of length `0` and returns it. This is syntactically valid because the return type is `int[]`; the length does not affect validity.

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 →

How Courseiva writes practice questions · Editorial policy

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.