Programming Language › Array in Java › Question #2197
Single Choice Not Set

QWhich one of the following is a valid statement?

ID: #2197 Array in Java 37,508 views
Question Info
#2197Q ID
Not SetDifficulty
Array in JavaTopic

Choose the Best Option

Click any option to instantly check if you're 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

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

Today: 0 answered · 0 correct
Save progress
Free account

Want to remember what you got wrong?

Create a free account in seconds to track your score, revisit mistakes and continue Programming Language where you left off.

  • Save your progress & streak
  • Topic-wise quizzes & scores
  • Bookmark tricky questions
  • Printable MCQ sets
Practice smarterFree account · save progress
Sign up free

Share This Question

Challenge a friend or share with your study group.