How do you declare a one-dimensional array in Java?
A. int[] myArray;
B. int myArray[];
C. Array
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.
Join The Discussion
Comments ( 1 )
Related Questions on Array
In Java, arrays are objects of which class?
A. Array
B. Collection
C. ArrayList
D. None of the above
How do you declare a one-dimensional array in Java?
A. int[] myArray;
B. int myArray[];
C. Array
D. All of the above
What is the default initial value of numeric elements in an array of type int in Java?
A. 0
B. 1
C. -1
D. Null
What is the correct way to initialize a two-dimensional array in Java?
A. int[][] myArray = {{1, 2}, {3, 4}};
B. int[2][2] myArray = {{1, 2}, {3, 4}};
C. int[2][2] myArray; myArray[0][0] = 1; myArray[0][1] = 2; myArray[1][0] = 3; myArray[1][1] = 4;
D. None of the above
why option B(int myArray[];) wrong we can declare in that way right