Sobes.tech
Junior — Middle

How is a static method created in Java?

sobes.tech AI

Answer from AI

In Java, a static method is created using the static keyword in the method declaration. Such a method belongs to the class itself rather than an instance, and can be called without creating an object of the class.

Example:

public class MyClass {
    public static void myStaticMethod() {
        System.out.println("This is a static method");
    }
}

// Calling the static method
MyClass.myStaticMethod();