I was asked today what is the default value of boolean in Java? It is false in my mind, but I don’t know if you have noticed. In fact, although the basic types have default values, if they are not initialized, they are used directly or the output fails to compile, just go to the code:
Direct compilation error, prompting that it cannot be used without initialization: the reason is that the variable a is not initialized.
Because the JVM does not assign values to local variables during class loading, it only assigns values to static member variables. Therefore, when the class is loaded, local variables have no initial values, and we must consider them to be initialized.
Compilation is successful, output default value: false