This is what I observe:
Outside of any methods in your class, there are two blocks. One labeled static and other unlabeled as anything. The unlabeled block is executed every time an object of this class is made. The static block is executed every time the class itself is invoked. In your program, the static block is invoked twice (when the program is first run and then when the initialization takes place every time).
I think this is how it is going:
1. When the class is being fired initially, the variable is getting initialized to 1 initially and then being set to 2 thru the static block.
2. At the time of instantiation again, the static block is first run and consequently the value is going to 4.
3. The final nail in the coffin is with the unlabeled block which literally acts like a constructor (terming it an initializer block is more appropriate) setting the value to 4*2 which is 8.
Good doubt this.. It makes one think..
By the way, were you deliberate in using a common variable name in several place?
Best Regards
Rahul :roll: