File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes where do static variable live? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "where do static variable live?" Watch "where do static variable live?" New topic

where do static variable live?

Naveen Kumar

Joined: Mar 12, 2008
Posts: 28
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.
Ashok Kumar Babu
Ranch Hand

Joined: Jul 25, 2006
Posts: 129
Static variables do exist within the class memory, it has nothing to d with the instance memory.

Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
Naveen Kumar

Joined: Mar 12, 2008
Posts: 28
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.
Aditya Singh
Ranch Hand

Joined: Mar 06, 2008
Posts: 62
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?
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
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.

SCJP - 86% - June 11, 2009
jQuery in Action, 3rd edition
subject: where do static variable live?
It's not a secret anymore!