This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Static initializer will be executed when the class is loaded, once you create instance of that class only instance initializer and constructors are executed, if you create multiple instance of class instance initializer and constructors are executed multiple times but static initializer will not.
Correct me if I am wrong When a class is loaded, first all static members are initialized, then all static blocks are executed in the order of declaration. But when the class is instatiated then if this class is derived from some superclass then the instance initalizer(s) of superclass(es), then constructor(s) of the superclass(es) then instace initializer of the class and finally constructor of the class is executed. And as Hetal said static blocks are not executed at the time of instatiation only at the time of loading
In other words....It is not that the value of si did not change. The static initialization block only gets executed one time. Since this is where you put the System.println call, it is only executed once.