I made a mistake, it's so sad
Thank you Xiaolong for noticing it.
And it must be called after A().
May be it is some kind of optimization
UN is compile time constant, and i is final.
May be compiler hints to JVM to initialize i with 1 and not with default 0.
It makes sense in every case except our example.
And test shows that it happens on practice.
Do one more test with the program.
to be first line of constructor B().
Class B now looks like this:
Compile it and run.
It prints i=0, j=0 for A and i=1, j=1 for B.
Note that i is still final here!
Interesting, we use final variable i even before it is assigned!
(check chapter 16 in JLS)
Where did you get this example? Is there anything else as good as this one?
[ February 24, 2005: Message edited by: Evgeni Shuster ]