Why LOCAL VARIABLES cannot be STATIC in Java ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why LOCAL VARIABLES cannot be STATIC in Java ??

Please Explain !!

23rd Dec 2016, 7:24 PM
Jenny Lance
Jenny Lance - avatar
2 Answers
+ 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
23rd Dec 2016, 10:10 PM
ReivaX
+ 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
25th Dec 2016, 5:06 AM
Gabe Rust
Gabe Rust - avatar