• Post Reply Bookmark Topic Watch Topic
  • New Topic

what about objects declare as static ?  RSS feed

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am aware about the static thing but still i want to ask you one question is that
while dealing with ints and doubles (in short primitives)
declare as static
in that if i increment one int by 1 then all the other instance of the same class will have the incremented value.
but what about objects declare as static ?
for eg :

 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it means you access the same variable from every instance. So if you assign a new instance of Logger to the variable, all instances of the containing class will see the same Logger when they access the variable.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Well, it means you access the same variable from every instance. So if you assign a new instance of Logger to the variable, all instances of the containing class will see the same Logger when they access the variable.


... which is exactly the same as what you get with primitives. That is, there is one variable shared by the class as a whole, and you see the same value whether you access it through the class name or through any instance reference.

@OP: Also, note that objects are never static or non-static. The attribute of "staticness" simply doesn't apply to them. It's the member variable that's static or non-static.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:The attribute of "staticness" simply doesn't apply to them. It's the member variable that's static or non-static.


That's pretty well summarized!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!