Results 1 to 13 of 13
Thread: static are instance variables
- 09-29-2008, 08:16 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
- 09-29-2008, 08:21 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
So what exactly do you want to discuss, as neither of those are correct.
- 09-29-2008, 08:28 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
ok only for the first point, where do those static attributes and methods are stored?
do you agree they must be part of an object?
- 09-29-2008, 08:35 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
Its hard for me to explain.
When i declare static methods and attributes, there must be an object that contains them to use them, isn't it?
After reading a bit JLS, i found that in Class initialization, static members are "incarnated" in the Class object.
- 09-29-2008, 08:49 PM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Class is also an "object", although one that you do not, normally, directly instantiate. The Class object that represents that Type is where the static methods and variables exist.
They are associated with the Class, not with any one instantiaed instance of that Class.
- 09-29-2008, 09:00 PM #6
Member
- Join Date
- Sep 2008
- Posts
- 5
- Rep Power
- 0
How's that association?
Aren't they "injected" to the class instance??
I said class instance, not instance of the class :)
- 09-29-2008, 09:14 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
:headdesk:
This was answered thoroughly in Sun's Java forums. I assume you are the same OP.
Reposting in another forum won't change the fact that primitives are not objects, nor will it change any of the other correct and thorough explanations you were given. If there's something you didn't understand about them, post your questions clearly and concisely in your original thread and they will be addressed.
- 09-29-2008, 09:16 PM #8
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
- 09-29-2008, 09:17 PM #9
Senior Member
- Join Date
- Sep 2008
- Posts
- 135
- Rep Power
- 0
Fyi
Hi masijade, long time no see! It may interest you to know that the OP recently raised this issue on Suns own Java forums, and got rather abusive when he failed to get the response he wanted
forums.sun.com/thread.jspa?threadID=5335355
What's missing is the now-deleted other thread where he announced his intent to get banned, and proceeed to slander several members of the forum with an amount of profanity
- 09-29-2008, 09:17 PM #10
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
Nope. Not sure why you'd think that.
Perhaps you think that all "data" must be stored in objects. That's not the case. An object only needs to hold object-specific data. Class variables (static member variables) are held in the Method Area of memory, as described in java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6656. This is where per-class information is stored, including the code for *all* methods--both static and non-static, and class variables. (Instance method code--non-static methods--can be stored there because executable code is read only.) The only thing that goes into objects on the heap is per-object data--instance member variables--and, depending on the implementation and what you view as composing an "object" at the level of VM memory allocation, some sort of pointer/reference/handle to the class definition for that object.Last edited by jverd; 09-29-2008 at 09:34 PM. Reason: Added detail.
- 09-29-2008, 09:34 PM #11
Senior Member
- Join Date
- Sep 2008
- Posts
- 135
- Rep Power
- 0
- 09-30-2008, 07:39 AM #12
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 09-30-2008, 06:30 PM #13
Senior Member
- Join Date
- Sep 2008
- Posts
- 135
- Rep Power
- 0
Similar Threads
-
accessing instance variables from static methods
By ravian in forum New To JavaReplies: 7Last Post: 03-01-2009, 10:09 PM -
Using Static Variables
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:08 PM -
Local Variables for a static method - thread safe?
By mikeg1z in forum Advanced JavaReplies: 1Last Post: 11-16-2007, 01:06 AM -
significance of static variables and methods
By imran_khan in forum New To JavaReplies: 4Last Post: 08-02-2007, 09:52 AM -
Help with static variables
By bbq in forum Advanced JavaReplies: 1Last Post: 06-28-2007, 05:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks