Which will legally declare, construct, and initialize an array?

  1. int [] myList = {"1", "2", "3"};

  2. int [] myList = (5, 8, 2);

  3. int myList [] [] = {4,9,7,0};

  4. int myList [] = {4, 3, 7};


Correct Option: D
Explanation:

To legally declare, construct, and initialize an array, the user needs to know the syntax of creating an array and how to initialize it with values.

Option A is incorrect because it uses double quotes for the array initialization, which is used for string values. For integer values, we don't need to use quotes.

Option B is incorrect because it uses parentheses instead of curly brackets for array initialization.

Option C is incorrect because it declares a two-dimensional array but only initializes with one-dimensional values.

Option D is correct because it declares, constructs, and initializes a one-dimensional integer array with the values 4, 3, and 7.

Therefore, the answer is:

The Answer is: D

Find more quizzes: