Question discussion

Which one of the following is a valid statement?

281500Medium 1 reply 3,356 views
34
Which one of the following is a valid statement?
  • Achar[] c = new char();
  • Bchar[] c = new char[5];
  • Cchar[] c = new char(4);
  • Dchar[] c = new char[];
Correct answer: B

Discussion 1

0
CCommunity
char[] c = new char[5];

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.