2016-01-27 19:00:40
0
class Test {
public static final int x;
public static void main (String[] args) {
Test.x = 42;
}
}
I have declared a static final variable, and when i compiled it the following error shown up.
error: cannot assign a value to final variable x
Test.x = 42;
i think i have reached to the solution but i want to check if i am right or not?
I know that a static variable if not initialized is provided a default value. As it is a static final int variable it will be assigned a value of 0. later on, i tried to change the value to 42 which is not possible because the variable is final and cannot be changed from 0.
am i right or is there some other answer to it?