+ 3
Why LOCAL VARIABLES cannot be STATIC in Java ??
Please Explain !!
2 ответов
+ 1
the static attribute enable the attribute or method to be called directly from the class. It must exist from the moment the class has been loaded in the Metaspace, therefore a local variable which doesnt exist until that method is called can't exist in the moment of loading the class
+ 1
A static variable is a class variable, which means it stays the same across all instances of the class, which would be impossible and pointless to do with local variables, which can't be accessed from outside their scope