- Class initialization starts. Initially,
foois null andsFlagis false - The first static variable initializer (
foo) runs:- A new instance of
Foois created - The instance variable initializer for
flagexecutes – currentlysFlagis false, so the value offlagis false
- A new instance of
- The second static variable initializer (
sFlag) executes, setting the value to true - Class initialization completes
mainruns, printing outfoo.flag, which is false
Note that if sFlag were declared to be final it would be treated as a compile-time constant, at which point all references to it would basically be inlined to true, so foo.flag would be true too.