Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In which order are classes loaded?

 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic