Examveda
Examveda

How do you declare a one-dimensional array in Java?

A. int[] myArray;

B. int myArray[];

C. Array myArray;

D. All of the above

Answer: Option A

Solution(By Examveda Team)

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:
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.

This Question Belongs to Java Program >> Array

Join The Discussion

Comments ( 1 )

  1. Pathina Anusha
    Pathina Anusha :
    3 months ago

    why option B(int myArray[];) wrong we can declare in that way right

Related Questions on Array