aspose file tools*
The moose likes Java in General and the fly likes are statics inherited? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "are statics inherited?" Watch "are statics inherited?" New topic
Author

are statics inherited?

Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
The static attributes and methods ("statics")are:
1) reachable without any eventual object instantiation (or before)
2)are unique between all instances
3)are bound at compile time
then "statics" are not inside Class' object's counterpart. Correct?
"Statics" are not inherited since 1),2), 3). Static method also is not inherited because:
a)it is not overridable (i.e. will not be called according to object's true type but according to reference type)? In other words, "statics" are just the repository independent of run-time, inheritance, reflection, etc. Correct?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I think that you have it correct.
Static variables are related to the class - not any object of the class.
Static methods are resolved at compile time and do not participate in polymorphism (stuff like overriding).
------------------
Cindy Glass
Sun Certified Programmer for the Java� 2 Platform
Co-author of Java 2 Certification Passport


"JavaRanch, where the deer and the Certified play" - David O'Meara
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
That were my starting points. Whether conclusions are correct that:
1)"statics are not inherited"; 2)"arenot inside Class objects"?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
"Inherited" is part of polymorphism -so no they are not inherited, but you can get at them from a subclass same as from any other class.
They are not "inside" any object. Methods (static and non-static) are NEVER "inside" an object. They live in the Method area in a separate area from the objects on the heap.
Static variables are kept with the Classfile and not with any objects - regular fields (non-static member variables) are kept with the object to define its "state".
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Wow, Cindy,
I did not hear abt method's area on the heap. I would really like to read anything about heap...
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
From the JVM Spec - The Structure of the Java Virtual Machine

3.5.4 Method Area
The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in a UNIX process. It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods (�3.9) used in class and instance initialization and interface type initialization.
The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java virtual machine specification does not mandate the location of the method area or the policies used to manage compiled code. The method area may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger method area becomes unnecessary. The memory for the method area does not need to be contiguous.
A Java virtual machine implementation may provide the programmer or the user control over the initial size of the method area, as well as, in the case of a varying-size method area, control over the maximum and minimum method area size.6
The following exceptional condition is associated with the method area:

If memory in the method area cannot be made available to satisfy an allocation request, the Java virtual machine throws an OutOfMemoryError.

------------------
Cindy Glass
Sun Certified Programmer for the Java� 2 Platform
Co-author of Java 2 Certification Passport
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Unbielivable! how I could dare started programming without knowing it
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Cindy Glass:
"Inherited" is part of polymorphism -so no they are not inherited, but you can get at them from a subclass same as from any other class.
By that token, non-virtual methods in C++ wouldn't be inherited either. Hmmmm... I would call them inherited, but other than instance methods they are resolved statically, at compile time (early binding).
- Peter
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
I also feel some misunderstanding with me and others abt statics. I think it is at the level of point of view and depends from your definitions, pre-suppositions. But Cindy took my sleep away, now I am reading JVM specs!
PS. Certainly I saw the tables with methods from Margaret A. Ellis, Bjorn Strostroup "The Annotated C++ Reference Manual"
It is the only book in programming that I have read out completely
[This message has been edited by G Vanin (edited November 22, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: are statics inherited?