Hi there,
I got the wrong answer to Q6 in the Self
Test Question for Chapter 3 of K&B 6. The question tests your knowledge of in what order static and non-static initialization blocks and constructors will run. I knew that the static init blocks would run before the non-static init block and constructors, but I wasn't sure of exactly when classes get loaded into the JVM, so I didn't know if the println() statement on the first line of main in a subclass would run before the static int blocks in the super class.
According to the answers, the static init blocks did run before the print() method on the first line of main. Cool, but my question is:
Which classes get loaded into the JVM and when?
Did the static init blocks in the Raptor class only run because the Hawk class had to be loaded to run the main method and that meant that all it's superclasses had to be loaded?
Or do absolutely all classes that are in java.lang get loaded and any others that have been declared as being imported?
Do a class and it's superclasses only get loaded just before they're needed in the code execution, or does it happen as soon as I call "java MyProgram"?
Also, what does it mean for a class to be loaded? What actually happen? Is it that a Class object gets created for that class?
As always thanks for your replies in advance.
Joe