What is the difference between java static method and instance method
This article mainly introduces the relevant knowledge of what is the difference between java static method and instance method, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this java static method and instance method. Let's take a look.
1. You can use the class name when calling static methods externally. The name of a method or object. Method name. There is only the second method for instance methods.
Static methods can be called without creating an object.
2. Static method class members are only allowed to access static members, not instance member variables and instance methods. There are no restrictions on instance methods.
Example
Public class staticMethodTest {void nonStaticMethod () {System.out.println ("This is a non static method");} static void staticMethod (staticMethodTest s) {System.out.println ("This is a static method"); s.nonStaticMethod ();} public static void main (String [] args) {staticMethodTest obj=new staticMethodTest (); staticMethod (obj);}} this is the end of the article on "what's the difference between java static methods and instance methods". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the difference between java static method and instance method". If you want to learn more knowledge, you are welcome to follow the industry information channel.