Java static method call and non-static method call

We can define a class when we first learn java (not learning object-oriented). Static methods can be written in the class, and the class name and method name can be used directly when calling. After learning object-oriented, after defining the class, you need to create an object and call the member methods or constructors of the class through the object. The following is the code difference between static method invocation (without creating an object) and non-static method invocation (define a rectangular class, define methods for finding perimeter and area, and then define a test class to test it):

Example 1: Static method invocation

Example 2: Non-static method invocation (object-oriented, set method and construction method are used when assigning values ​​to objects):

 

Published 4 original articles · received 1 · views 187

Guess you like

Origin blog.csdn.net/joeychiang/article/details/104139664