Suppose you want to declare an array of the first five letters of the alphabet. How do you declare and initialize the array?

  1. char[] alpha = {'A', 'B', 'C', 'D', 'E'};

  2. char[] alpha = {"A", "B", "C", "D", "E"};

  3. char[] alpha = new char('A', 'B', 'C', 'D', 'E');

  4. char[][] alpha = {{'A', 'B', 'C', 'D', 'E'}};


Correct Option: A
Explanation:

To solve this question, the user needs to know how to declare and initialize an array in Java.

Option A is correct since it declares an array of characters and initializes it with the given values separated by commas within curly braces. This is the correct syntax for initializing a character array in Java.

Option B is incorrect because it uses double quotes (") instead of single quotes (') to initialize the characters. In Java, double quotes are used for Strings while single quotes are used for characters.

Option C is incorrect because the syntax for initializing an array using the "new" keyword is incorrect. The correct syntax is to use square brackets after the data type to specify the size of the array.

Option D is incorrect because it declares a two-dimensional array instead of a one-dimensional array. The inner curly braces are not needed since there is only one dimension.

Therefore, the correct answer is:

The Answer is: A. char[] alpha = {'A', 'B', 'C', 'D', 'E'};

Find more quizzes: