frank neiderhiser wrote:
Also, what is the difference between x++ and static{x++};
The "static { }" part of the code, in your example, is a static initializer. That code is run when the class is loaded, and ran with static variable initialization and other static initializers, in the order that they are encountered in source code. So ....
frank neiderhiser wrote:
Ignoring the main() method for the moment, when the class is loaded, a static variable "x" is allocated, and assigned the value of 7; then that variable is incremented in the static initializer. And then, the main() method is called.
Henry