• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static variable question

 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that

the vale of a static variable is different within a same JVM at different code locations at SAME point of time ? ( Of course nobody modified the value at any point of time)
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that's gobbledegook. Please have another go at explaining your question.
 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok , Suppose I create a static variable inside a class.

Class myclass{

Static String aa = �xyz�;
///
///

}


Now this class variable is used in different places in the code.

Sysout ( �The value is �+ Myclass.aa);


In ideal case, every time the variable is accessed , it should print / return the "xyz" value.


My question is , Is there any possibility that the value of aa will be returned different than �xyz� ( Say null )anywhere in code?
( Nobody changes the string aa or assigns null to it)
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a beginners' question, but if nobody alters the value it ought to remain "xyz". I can't think of any way it can change, but of course somebody might reassign it while you are not watching.
Better to write

public static final String xzy = "xyz";

CR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic