A method that belongs to a class. The definition of the class method is "public static return type method name ()". Class methods can be called without instantiating. [Example] Person class
Person.java
class Person {
public static return type method name() {
//Method processing
}
}
[Example]
Main.java
class Main {
public static void main(String[] args) {
~abridgement~
Person.printCount();
}
}
Person.java
class Person {
public static int count = 0;
~abridgement~
public static void printCount() {
System.out.println("The total is" + count + "is");
}
}
Recommended Posts