1. The main method is static, but why is it not static.
The reason is that if a class defines the main method, its main method will be called before the constructor of the class runs.
Because the corresponding object has not been generated in JVM during the main method running (the constructor is not executed), it is necessary to declare static.
2. This involves the following issues. Like any other method, the static method can create or use named objects of the same type as other methods. Therefore, the static method is often used as the "Shepherd" role to take care of instances of the same type as it belongs."
In fact, the author means that, according to the GOF (pattern for the four-person gang) viewpoint, the production method of a single instance factory class should be static.
In the object-oriented language, the highest level is the meta class. The meta class is the class, and the class is the object. For virtual machines, classes are meta-class objects, and static methods are class methods, rather than object methods.
Therefore, the object is equivalent to a "goat", and the class is equivalent to a "sheepfold" for storing and marking the "goat". To get out a goat, ask, which sheepfold are you in?
The static method is equivalent to the "Dog in the sheepfold" and is dedicated to managing sheep.
The Meta class is the "Shepherd" behind the scenes '.
Thinking's undergraduate course was written in books, and later he switched to Software Engineering (c was learned at that time). It may be the reason why thinking came home, and he had a different understanding of the object-oriented mechanism.
3. For details, the "static method is the method without this" clause is actually nonsense. this is an object reference. The static method is a class method, not a specific object method, so it is meaningless to use this reference in the static method.
4. I love whether static methods and static attributes are stored in one place.
I can say responsibly that they cannot store them in the same memory address (Laugh), except for virtual addresses.
In fact, they do not belong to any specific object, so they do not appear in the memory block allocated for which specific object.
As I mentioned earlier, the static method and static attribute belong to the class, so they are stored in the memory space of the corresponding class.
Why does the class still have its own memory? Because a specific class is an object of a specific meta class. That is to say, a class is an object of another class. This Meta class is not open to application programmers.
In fact, static is a very old keyword. It is older than most friends here.