Categorical variables and instance variables & class methods and instance methods

Class variables and instance variables

Definition: The variable described with the modifier static is a class variable, and the others are instance variables. The
difference: instance variables of different objects will be allocated different memory spaces; and class variables of all objects are allocated to the same memory, change one of them The value of a class variable of an object will affect the value of this class variable of other objects.

Instance method and class method

Definition: The method modified with the modifier static is a class method, and the others are instance methods.
Difference: When a class creates an object, the object can call the method of the class. The difference is that the class method can not only be called by the object but also can be called directly by the class name, while the instance method cannot be called by the class name.

Guess you like

Origin blog.csdn.net/zhanlong11/article/details/114312109