This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static variable question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static variable question" Watch "Static variable question" New topic

Static variable question

Hrishikesh Ghatnekar

Joined: Oct 25, 2004
Posts: 28
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

Joined: Oct 30, 2001
Posts: 1970
Sorry, that's gobbledegook. Please have another go at explaining your question.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Hrishikesh Ghatnekar

Joined: Oct 25, 2004
Posts: 28
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

Joined: Oct 13, 2005
Posts: 43381
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";

subject: Static variable question
It's not a secret anymore!