static method
时间: 2023-09-24 07:13:08 浏览: 42
In Object-Oriented programming, a static method is a method that belongs to a class rather than an instance of that class. This means that the method can be called without creating an instance of the class and is shared among all instances of the class.
Static methods are commonly used to define utility functions or methods that perform some operation that doesn't depend on the state of an object. They are also used to create factory methods that return instances of a class, or to define constants that are related to the class.
To define a static method in Java, we use the "static" keyword before the method signature. For example:
```java
public class MyClass {
public static void myStaticMethod() {
// Code here
}
}
```
To call a static method, we use the class name followed by the method name, like this:
```java
MyClass.myStaticMethod();
```