Static blocks -are static ,they run when class is loaded and not associated with any instances /objects of class or constructor(constructor constructs an object)
"Except if the static fields are only used through instance methods, then you can do lazy initializing through the constructor."
I am really interested in the exceptional case that you mentioned.Can you please provide some examples to explain better.
Stephan van Hulst
Joined: Sep 20, 2010
Here is such an example. Let's say Expensive objects are very expensive to create. You don't want to create them until you really have to. If the Expensive object is only used by instance methods, like plus(), you can avoid creating one until the first instance of Test is created. This way, if a program only needs the help() method, it can avoid creating a Test (and thus an Expensive) altogether.
This is a rare situation, but it's just an example.