Showing posts with label java static constructor. Show all posts
Showing posts with label java static constructor. Show all posts

Tuesday, December 20, 2011

Are static fields initialized before constructor is called?

I've encountered this while debugging one very strange issue in third party library. Decompiled code made this case even more interesting and not so obvious.

How do you think, what is the output for following program?



Output is:

null
2
1
2

Constructor is called before "staticField" is initialized.