The difference between static method and instance method is mainly embodied in two aspects:
When you call a static method externally, you can use the "class name. Method Name" way, or you can use the "object name. Method Name" way. The instance method is only in the following way. That is, calling a static method eliminates the need to create an object.
When a static method accesses members of this class, it only allows access to static members (that is, static member variables and static methods), not to instance member variables and instance methods, and the instance method does not.
The following diagram shows this difference.
The difference between a static method and an instance method:
Use/Invoke |
Static methods |
Instance method |
Own local variables |
√ |
√ |
static variables |
√ |
√ |
Static methods |
√ |
√ |
Instance variable |
X |
√ |
Instance method |
X |
√ |
Differences between JAVA static methods and instance methods (chart)