Anishashu Sharma wrote:Static Variables are initialized and Static Blocks are executed when class is first loaded.
i don't think they are initialized at class loading time. they are initialized during class initialization which occurs after class loading. according to JLS class initialization involves inititalization of class variables and static initializer (static init blocks). class initialization occurs just before the first occurence of following: Say T is a class and
1. instance of T is created
2. static method of T is invoked
3. static variable of T is accessed
4. static variable of T is assigned and it is NOT a compile time constant.