File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing non-static from static context error

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following code snippet in that subclass.java throws an error message that non-static getNumber() method cannot be referenced from static context.





Whats wrong in subclass.java code, I am not accessing getNumber() method from within main method which is static? Can anybody please let me know?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The initialization of static members like "a" happens in a static method named "<clinit>", specially created by the compiler to hold such code. So you are, indeed, calling getNumber() from a static method.

Most likely your real code is more complex, but in this case, since all getNumber() does is provide access to a static member, why can't it be static?

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic