Java – a variable be declared as static and final

finaljavastatic

A variable is declared as static to get the latest and single copy of its value; it means the value is going to be changed somewhere. But why should the same variable be declared as final, which will not allow the variable to be changed else where (constant value)?

Best Answer

static so that the variable or method can be accessed without creating a class instance, and there is only one variable for the class instead of one for each instance.

A final class cannot be extended. A final variable cannot have its value changed, it behaves as a constant. And a final method cannot be over-ridden.