?
How do you declare a one-dimensional array in Java?
Answer & Solution
Correct Answer:
Option
A
In Java, a one-dimensional array is declared by specifying the type of elements followed by square brackets and then the array name. The correct syntax is:
Option A follows this syntax and is the correct way to declare a one-dimensional array in Java.
Option B is also a valid syntax but is less commonly used. Both Option A and Option B are equivalent.
Option C is incorrect as it attempts to use generics syntax, which is not allowed for arrays in Java.
Option D is incorrect because Option C is not a valid way to declare an array.
type[] arrayName;Option A follows this syntax and is the correct way to declare a one-dimensional array in Java.
Option B is also a valid syntax but is less commonly used. Both Option A and Option B are equivalent.
Option C is incorrect as it attempts to use generics syntax, which is not allowed for arrays in Java.
Option D is incorrect because Option C is not a valid way to declare an array.
Join the Discussion
Login to post a comment or share your explanation.
Login