This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Reassigning class variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reassigning class variable" Watch "Reassigning class variable" New topic

Reassigning class variable

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Here i is a class variable, are we allowed to change value assigned to class varaible ?

D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
You can reassign any variable that is not marked "final". Note however that what you have in your example is NOT a class variable (marked with "static"). Class variables only exist once, regardless how many object instances you create. So if one object changes the value, all other instances will see the change. Instance variables (such as your variable "i") on the other hand exist for each object instance, so a change in one instance won't be noted in any other instance.
jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Thanks a lot for your response
wood burning stoves
subject: Reassigning class variable
Similar Threads
inner class/inheritance
assigning one primitve variable to another primitive variable..
instanceof Operator
object garbage collection.
Basic thread doubt