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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 thatMatheven allows instances to be constructed)? Or a different case insensitive ordering for each instance ofString?