Which one of the following is a valid statement?
A. char[] c = new char();
B. char[] c = new char[5];
C. char[] c = new char(4);
D. char[] c = new char[];
Answer: Option B
Solution (By Examveda Team)
The syntax for declaring and creating an array variable in java is:
dataType[] arrayRefVar = new dataType[arraySize];
Thus, option (A) and option (C) is syntactically wrong as parentheses( ( ) ) is used instead of square brackets( [ ] ).
Option (D) is incorrect as the size of the array is missing.
Join The Discussion
Comments (5)
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 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

all option are similar .so,how we differentiate they
All option are same and also invalid option.
All option are same and also invalid option.
all options are same.How can we differentiate in between them?
all option are same and invalid