Courseiva
Question 18 of 481
Arrays and MethodsmediumMultiple SelectObjective-mapped

1Z0-811 Arrays and Methods Practice Question

Which TWO are valid ways to pass an array to a method in Java?

⚠ Common exam trap

Candidates often confuse array initializer syntax with array creation syntax, mistakenly thinking `int[] {1,2,3}` or `new int[5] {1,2,3,4,5}` are valid, when Java requires either a declaration with an initializer or an anonymous array creation with `new` and no size specifier.

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

myMethod(new int[]{1,2,3});

`new int[]{1,2,3}` is an anonymous array creation expression that creates a new int array and passes it directly to the method. This syntax is valid in Java for passing an array literal without a variable. Option B is correct because it declares an array variable `arr` initialized with an array initializer `{1,2,3}` (which is allowed only in a declaration statement) and then passes that reference to the method, which is a standard way to pass an 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.

  • myMethod(new int[]{1,2,3});

    Why this is correct

    This option demonstrates an anonymous array creation and initialisation. The syntax `new int[]{1,2,3}` allows for the inline instantiation of an `int[]` object directly within the method call, without requiring a separate variable declaration. The newly created array, populated with the specified elements, is then passed immediately as an argument to `myMethod`. This is a valid and frequently utilised mechanism for passing an array to a method in Java, satisfying the question's requirement.

  • int[] arr = {1,2,3}; myMethod(arr);

    Why this is correct

    Passing the array reference.

  • myMethod(1, 2, 3);

    Why it's wrong here

    Method expects an array, not individual ints.

  • myMethod(int[] {1,2,3});

    Why it's wrong here

    Missing 'new' keyword; should be new int[]{1,2,3}.

  • myMethod(new int[5] {1,2,3,4,5});

    Why it's wrong here

    Cannot specify size when using initializer.

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 25, 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.