• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static method access non-static variable?  RSS feed

 
Serena Zhou
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static method cannot access non-static variable in general. But is there any way to do it?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanc, Jing Zhou!
Concerning your question, what would it mean if you could access a non-static member from a static context? Why would you want to do such a thing?
Note that from a static context, you can have a (static) reference to an instance of some object, and through that reference you can access members of the instance it refers to.
 
Serena Zhou
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!