Java SE 8 Programmer I — Question 132
Which two array initialization statements are valid? (Choose two.)
Answer options
- A. int array[] = new int[3] {1, 2, 3};
- B. int array[] = new int[3]; array[0] = 1; array[1] = 2; array[2] = 3;
- C. int array[3] = new int[] {1, 2, 3};
- D. int array[] = new int[3]; array = {1, 2, 3};
- E. int array[] = new int[] {1,2,3};
Correct answer: B, E
Explanation
Option B is valid because it properly initializes an array with a specified size and assigns values to each index. Option E is also valid as it correctly initializes an array with predefined values using the new int[] syntax. Options A, C, and D are incorrect due to syntax errors in array initialization.