1. Class method
Class method is a static method and needs to be modified by the static modifier in front. Variables cannot be included in class methods.
1. The object method of the class cannot be called
2. The object variable cannot be referenced
3. The class method cannot be overridden (overwritten)
4 , Class methods cannot use super, this keyword
2. Instance methods
1. You can call the object method of the class
2. You can quote Object variables
3. Instance methods can be overridden (overwritten)
4. Instance methods can use super, this keyword
Difference:
The class method is assigned a memory address when the class is loaded, so it can be called by any object after loading, and can be called directly through the class name (class name. method name), while the instance method needs to be created after The memory address will be allocated after the object.
Recommended tutorial: Java tutorial
The above is the detailed content of The difference between class methods and instance methods in java. For more information, please follow other related articles on the PHP Chinese website!