Instance method/class method, instance method
1. instance method/Dynamic Method
A). identifier :-
B). Call method: (Instance Object Function)
C). The instance method is on the stack.
2. Static methods/class methods
A). identifier: +
B). Call method: (Class Functions)
C) The static method allocates memory on the heap.
3. Distinction between static methods and instance methods
A) The static method is resident memory, and the instance method is not. Therefore, the static method is highly efficient but occupies the memory. In fact, the methods are the same. In terms of loading time and memory usage, the static method is the same as the instance method, and is loaded when the type is used for the first time. There is basically no difference in the call speed.
B) The static method allocates memory on the stack, and the instance method is on the stack. In fact, it is impossible for all methods to allocate memory on the heap or stack. As code, methods are loaded into special code memory areas, which cannot be written.
C) The instance method can be called only after an instance is created. It is troublesome and the static method is not needed. It is relatively simple.
D) The static method is statically bound to the subclass, not inherited.
E). Generally, static methods are used frequently, and dynamic methods are used in a few ways. Static speed is fast, occupying memory. The dynamic speed is relatively slow, but the class is released immediately after the call, which can save memory. You can choose whether to use the dynamic method or static method as needed.
F) The static method modifies the class state, while the object modifies the state of each object.
G). The instance call of the class exists in the life cycle of the class. When the class does not exist, the corresponding instance does not exist and the corresponding method does not exist. Static classes do not exist until you reference the static class namespace.