nerdexam
Oracle

1Z0-803 · Question #84

Which two are valid array declaration?

The correct answer is A. Object array[]; C. int[] array. In Java, arrays can be declared by placing square brackets either after the type name or after the variable name.

Creating and Using Arrays

Question

Which two are valid array declaration?

Options

  • AObject array[];
  • BBoolean array[3];
  • Cint[] array;
  • DFloat[2] array;

How the community answered

(55 responses)
  • A
    93% (51)
  • B
    2% (1)
  • D
    5% (3)

Why each option

In Java, arrays can be declared by placing square brackets either after the type name or after the variable name.

AObject array[];Correct

The syntax `Object array[];` is a valid way to declare an array in Java, where the square brackets are placed after the variable name.

BBoolean array[3];

Array size cannot be specified during declaration; it must be provided during initialization using the `new` keyword.

Cint[] array;Correct

The syntax `int[] array;` is the most common and preferred way to declare an array in Java, with the square brackets placed after the type name.

DFloat[2] array;

Similar to option B, array size cannot be specified within the square brackets during the declaration phase.

Concept tested: Java array declaration syntax

Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Topics

#array declaration#array syntax

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice