MCQ Practice Single Best Answer Topic: Array in Java

Q Which one of the following is a valid statement?

Question ID
#2197
Subchapter
Array in Java
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A char[] c = new char();
  • B char[] c = new char[5];
  • C char[] c = new char(4);
  • D char[] c = new char[];
Correct Answer: B

Explanation

char[] c = new char[5];

This line of Java code creates a new array of characters called "c" with a length of 5.

The "new" keyword is used to allocate memory for the array, and the "char[]" indicates that it is an array of characters. The number inside the square brackets [] specifies the size of the array, which in this case is 5.

So, the resulting variable "c" is an array that can hold up to 5 characters. Note that the elements of the array are initially set to the default value of the char data type, which is '\0' (the null character).

Share This Question

Share this MCQ with your friends or study group.