Question 14
Back to Exercise
What is the output of the following Java program?
import java.util.Arrays;
public class Main {
static final int[] DAYS = {31, 28, 31};
public static void main(String[] args) {
DAYS[1] = 29;
int[] alias = DAYS;
alias[2] = 30;
System.out.println(Arrays.toString(DAYS));
}
}
- A [31, 29, 30] Correct
- B [31, 28, 31]
- C Compilation error
- D [31, 29, 31]
Correct Answer: Option A
A final array reference still allows its elements to change – a "constant" array is not really constant. Use List.of for an unmodifiable list.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!