Why are Java constants declared static
?
class Foo {
static final int FII = 2 ;
}
In this example I understand the use of final
, But why does it have to be static? Why should it be a class variable and not an instance variable?
If it could vary by the instance of a class, then it's clearly not a constant. What would it mean to get a different value of pi for each instance of Math
(not that Math
even allows instances to be constructed)? Or a different case insensitive ordering for each instance of String
?