Some may find it similar to the SO question Will Java Final variables have default values? but that answer doesn\'t completely solve this, as that question doesn\'t directl
The difference is that in the first case you are calling System.out.println
from initializer block so the block which is invoked before constructor. In the first line
System.out.println(x);
variable x
is not yet initialized so that you get compilation error.
But in the second case you call instance method which doesn't know if variable has already been initialized so you don't have compilation error and you can see the default value for x