Static initializer code in the Parent class will execute once when the Child class is loaded (because this will also load the Parent class) -- whether or not an instance of either class is created.
Classes are loaded automatically by the JVM either when the first object of that class is created or the first time a static member of that class is accessed -- even if no object is created. (Alternatively, a class can be loaded "manually" using Class.forName(String).)
Non-static initializer code executes with each instantiation.
[ October 08, 2004: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Originally posted by Mike Gershman: If the parent class was already loaded for one of the reasons mentioned, its static initializers won't run again when the child class is loaded...
Yes, that's a good point. I should have been more clear in my first paragraph. Static initializers run only once, at class load time. And if the Parent class is not already loaded, then loading the Child class will also load the Parent class. [ October 08, 2004: Message edited by: marc weber ]