I am having trouble understanding why in Java static methods can't access nonstatic variables. Could anyone explain the reasoning behind such a language design choice?
Asked
Active
Viewed 35 times
0
-
1Non-static variables are associated with a particular instance; static methods are not. – Andy Turner Feb 16 '17 at 12:54
-
1you can learn this article here : https://www.quora.com/Java-programming-language-Why-cant-a-static-method-directly-access-non-static-members – Youcef LAIDANI Feb 16 '17 at 12:55
-
Still I don't see the intuition behind such a design choice, Why the method can't access the non static data? Why does the compiler shoot out an error like "non-static variable u cannot be referenced from a static context"? – guser Feb 16 '17 at 13:00
-
1@YCF_L Thanks for the quora link now I see – guser Feb 16 '17 at 13:02