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.
Question
Which two are valid array declaration?
Options
- AObject array[];
- BBoolean array[3];
- Cint[] array;
- DFloat[2] array;
How the community answered
(55 responses)- A93% (51)
- B2% (1)
- D5% (3)
Why each option
In Java, arrays can be declared by placing square brackets either after the type name or after the variable name.
The syntax `Object array[];` is a valid way to declare an array in Java, where the square brackets are placed after the variable name.
Array size cannot be specified during declaration; it must be provided during initialization using the `new` keyword.
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.
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
Community Discussion
No community discussion yet for this question.