The Static varible will be created and initilized before the static block. As Balazs point out in his post, The x created in the static block is a new x which only has scope in the static block. Instead of using int x = 5 in the static block, try using this.x = 5 or Static.x = 5. The static varible has to exist before you can work with it. Therefore, the static varible is created and initilized before the static block.
In the explanation with the code I gave before said that the static block variable will not have any effect on the output because it declares a new variable. I got it. But what if I want to access that static block variable in the main method, can I do it? If yes how do I do it?
I am so confused about this static blocks and variables .
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad: