Courseiva
Arrays and MethodsmediumMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

A developer writes a method that accepts a variable number of int arguments and returns their product. Which method signature correctly implements this?

⚠ Common exam trap

Oracle often tests the requirement that varargs must be the last parameter, and the trap here is that candidates might think `int nums...` is valid or that a regular array parameter qualifies as variable arguments.

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

public static int product(int... nums)

The syntax `int... nums` is the proper Java varargs syntax, allowing a method to accept zero or more `int` arguments, which are then treated as an array inside the method. This enables the developer to call `product(2, 3, 4)` or `product()` and compute the product by iterating over the array.

Answer analysis

Option-by-option breakdown

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

  • public static int product(int[] nums)

    Why it's wrong here

    This is not varargs; it requires an array argument.

  • public static int product(int nums...)

    Why it's wrong here

    Invalid syntax; ellipsis after type.

  • public static int product(int... nums)

    Why this is correct

    Varargs correctly declared.

  • public static int product(int... nums, int extra)

    Why it's wrong here

    Varargs must be the last parameter.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.