IntelliJ Java IDE
The moose likes Java in General and the fly likes Reassigning class variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Reassigning class variable" Watch "Reassigning class variable" New topic
Author

Reassigning class variable

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 261
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: 181
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: 261
Thanks a lot for your response
 
 
subject: Reassigning class variable
 
Threads others viewed
instanceof Operator
inner class/inheritance
assigning one primitve variable to another primitive variable..
object garbage collection.
Basic thread doubt
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture