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 In which order are classes loaded? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "In which order are classes loaded?" Watch "In which order are classes loaded?" New topic

In which order are classes loaded?

Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
I have defined a class Father and another class Son extending Father. They both have static blocks. When creating the first Son-instance always the static block of the Father-class is executed and after that Son's static block. As far as I understand that means that the Class Loader loads the Father-class first and then the Son-class. Right? If so:

Will that always be that way? Is there a specification for the JVM that will garantie such a performance or is it unpredictable in what way classes will be loaded on an arbitrary system?
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Reader,
I guess it follows the hierarchy of the Son object.
If 3 extends 2 extends 1..
then static method of 1 will be called first (if any).. and then down the hierarchy.. Not too sure though..

With Best Regards,
Shyam Prasad Murarka
I agree. Here's the link:
subject: In which order are classes loaded?