0

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?

guser
  • 296
  • 2
  • 12
  • 1
    Non-static variables are associated with a particular instance; static methods are not. – Andy Turner Feb 16 '17 at 12:54
  • 1
    you 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

0 Answers0