I am trying to understand what happens if I reassign a value to array element which is final, this is the code :
public class XYZ {
private static final String[] ABC = {"Hello"};
public static void main(String[] args){
System.out.println(ABC[0]);
ABC[0] = " World!!!";
System.out.println(ABC[0]);
}
}
ABC is final array and at first position it have "Hello"
initially, but when I reassign it to " World!!!"
it should either over ride the previous value or it should give compilation error for reassigning to final variable. This program runs fine and this is the output :
run:
Hello
World!!!
BUILD SUCCESSFUL (total time: 0 seconds)