Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reassigning class variable

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here i is a class variable, are we allowed to change value assigned to class varaible ?

 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your response
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic