The methods in the class body are divided into instance methods and class methods, and the class method is modified with static.
Class method:
For class methods in a class, when the class is loaded into memory, the corresponding ingress address is assigned. Thus, a class method can be invoked not only by any object invocation created by the class, but also directly through the class name. The entry address of the class method is not canceled until the program exits.
Example method:
When a class's bytecode file is loaded into memory, the instance method of the class is not assigned the entry address, and the instance method in the class assigns the entry address after the class creates the object, so that the instance method can be executed by any object that the class creates. It is important to note that when we create the first object, the instance method in the class assigns the entry address, and when the object is created, the entry address is no longer assigned, that is, the entry address of the method is shared by all objects, and when all objects are absent, the method's entry address is canceled.
——————————————————————
Member variables are divided into instance variables and class variables, and variables modified with static are class variables.
Class variables:
Class, when the class is loaded into memory, the corresponding memory space is allocated. If a member variable in a class has a class variable, the class variable of all objects is assigned to the same memory, and changing the class variable of one of the objects affects the class variable of the other object. This means that the object shares class variables.
Instance variable:
Instance variables for different objects will be allocated different memory spaces
Java class methods and instance methods, and class and instance variables