File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Static Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static Methods" Watch "Static Methods" New topic
Author

Static Methods

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Ok, if I have Class A and it contains 4 static methods.
Then lets say I have 4 more Classes, Class B, Class C, Class D, and Class E.
Now, if I instantiate Class A in B, C, D, and E is there still only 1 instance of each of the static methods in memory from Class A?


GenRocket - Experts at Building Test Data
khella smith
Ranch Hand

Joined: May 06, 2002
Posts: 39
i suppose so because when once u have a static method in a class no matter how many instances of that class u have the method stays the same because it is only loaded once at compile time so i suppose the same would apply for instanciating class a in different class since that static method is in class a alone i suppose it will still stay the same
correct me if i am wrong
i'll appreciate it
----------------
khella smith
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Methods are not replicated per object.
Methods are kept in a special "method area" with the Classfile. Some of those methods are tracked as Static and some as member methods.
When a method is invoked the JVM ALWAYS goes to the classfile to find the code to execute. It is over in "classfile-land" that polymorphism takes place.
The only things that actually reside in an object are the variables that track state and a "type" identifier.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Methods