• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

where do static variable live?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The copy of instance variable live within each instance of a class.
But where do static variable live?.since there is only one copy of the class.
within which object the static variable lives.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static variables do exist within the class memory, it has nothing to d with the instance memory.
 
Naveen Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
every variable either instance or static will live within the object.each instance variable will have a seperate copy within each object.
Then an static variable should also be within the Class Object of the class. i think so.
I may be wrong also.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static variable are accessible to all instances no doubt. They are stored in Data Segment(book says so!). Wel it does not make sence to giv a copy of static variable to each instance after all we need only one variable then why to duplicate the code?
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could also be off the mark here, but I thought that static variables were accessible without ever instantiating an object. If you never instantiate one then there wouldn't be any "instance" for it to be a part of. I think it is in some other sort of memory pool where classes are loaded but I have no idea where that might be.
 
That feels good. Thanks. Here's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic