Courseiva
Arrays and MethodseasyMultiple SelectObjective-mapped

1Z0-811 Arrays and Methods Practice Question

Which TWO are valid ways to declare and initialize an array of Strings?

⚠ Common exam trap

Oracle often tests the distinction between array declaration syntax and the two valid initialization forms, trapping candidates who think `new String[2]` initializes with given values or that `{"A", "B"}[]` is a valid shortcut.

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

String[] names = new String[]{"A", "B"};

It uses the valid syntax `new String[]{"A", "B"}` to both declare and initialize a String array in a single statement. This is the standard way to create an array with an anonymous array initializer when the declaration and initialization are combined.

Answer analysis

Option-by-option breakdown

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

  • String[] names = {"A", "B"}[];

    Why it's wrong here

    Invalid syntax with brackets after initializer.

  • String names[] = new String[2];

    Why it's wrong here

    Valid but initializes with nulls, not with values.

  • String[] names = new String[]{"A", "B"};

    Why this is correct

    Valid anonymous array creation.

  • String[] names = {1, 2};

    Why it's wrong here

    Type mismatch; ints cannot be assigned to String array.

  • String names[] = {"A", "B"};

    Why this is correct

    Valid C-style declaration with initializer.

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.