The static method is the method without this. Non-static methods cannot be called within the static method. In turn, non-static methods can call static methods.
It is worth noting that non-static methods cannot be called directly within the static method, but non-static methods can be called by generating objects.
In the static method, non-static variables cannot be called. In fact, the principle is very simple, because static is global-oriented and equivalent to a global method, and cannot be used only for general variables in a class.
Static variables (global variables) cannot be declared in both static and non-static methods, because the variables declared in the method are local variables and it is impossible to define a global variable in them.
After understanding the above knowledge, you may find a special case: on the fourth version of the programming idea p157, the constructor is implicitly static! However, why can I directly call non-static methods in the constructor ??
Explicit and implicit static refers to the code that the system will execute during class instantiation.
For example
Class statictest... {// if there is no static keyword, it is called implicit static. After the system executes the explicit static statement, it will then execute the Implicit Static code.
...{
System. Out. println ("Hide static ");
Show (); // This method is not static, but there is no error here
}
Static... {// This static keyword is called explicit static. The system will first execute the explicit static code.
System. Out. println ("static ");
// Show (); // This method is not static, so an error occurs.
}
Public statictest ()... {// After the explicit and implicit static statements are executed, the system will execute the constructor code because the constructor is not static but will also be executed, just like the Implicit Static statements, so the book calls it Implicit Static.
System. Out. println ("constuctor ");
}
Public void show ()...{
System. Out. println ("show ");
}
Public static void main (string [] ARGs )...{
New statictest ();
}
}
So Explicit Implicit Static is only for the sequence of code execution by class instantiation. In a sense, all code without static can be called implicit static, implicit Static can call non-static members.