Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

strange behaviour of static in java 5  RSS feed

 
nan priya
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i tried to modify a class level static vaiable via method.the method is non static and the change reflects in the method call as well striaght call in the method.! pl let me know the reason..
 
sentil kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static variable can be accessed from static and non-static method.
because it is common to everybody
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... the change reflects in the method call as well striaght call in the method.

What do you mean? Please explain with some sample code. As Sentil says, static member variables are class-level variables: there is only one copy of the variable, which is shared by all instances of the class. Static variables can be accessed by static and non-static methods.

See this chapter in The Java Tutorial: Understanding Instance and Class Members

(This doesn't sound like a question that belongs in the Advanced forum).
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!