A static method uses a common memory space, meaning that all objects can be referenced directly, and no object needs to be created to use the method.
For example, I create a class that has a static method:
Class test{
public static int Z (int xx,int yy) {
return xx+yy;
}
public int zz (int xx,int yy) {
return xx+yy;
}
}
Then, when using this class in a class that contains the main method, the reference to the non-static and static methods is different, as follows:
Import Test;
public class mainclass{
int sum;
public static void Main (String args[]) {
(SUM=TEST.Z); The method or property can be used directly with a class. Method or property.
SYSTEM.OUT.PRINTLN (sum);
Test t=new test ();
(SUM=T.ZZ); Because ZZ is not a static method, you can only create a T object with the test class and then call the method of that object.
SYSTEM.OUT.PRINTLN (sum);
}
}
What is a static method