Why can’t Final variables be accessed in a static variables.
At the compile time they are simply substituted directly substituted with their values
so, they should be allowed to use even in static methods
why is this restriction???
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.
Not all
finalvariables are compile time constants. Onlystatic finalvariables can be substituted by compiler as compile-time constants.finalmodifier in certain cases is only used to ensure const-correctness.And
staticmethods cannot access non-static variables as those variables can have different values for different instances of the same class.