static Keyword in Java


The static keyword in Java means that a particular field or method belongs to a class, rather than instances of that class.

Source Code

public class MyClass {
    static void myStaticMethod() {
        System.out.println("Static methods can be called without creating objects");
    }
    public static void main(String[] args) {
        myStaticMethod(); // Call the static method
    }
}

Use static for methods or fields that should be shared across all instances of a class.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments