This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Take special note of the line in the static initializer:
See the "int" at the beginning of that line? Due to that, we don't assign 5 to the class variable, we create a new local variable and assign 5 to that. The class variable, Static.x is initialized to 0.
Then, to start the main method, we decrement x, taking it to -1.
When we invoke myMethod, we get this:
So, when the assignment is applied x is equal to 1 and y is set to 0.
Finally, back in the main method, we execute this line:
Hopefully, that helps you see why you get the result that you do.