Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    What Is static Variables and Methods in Java?

    You might have used the keyword static in Java several times, let us now understand the use of it. In the Java language, a static keyword is implemented to make a class-level variable. Hence variables and methods having the static keyword act as part of the class and not as the class instance.

    static keyword can be used with a variable of any class. These types of variables do not belong to the object (or you can call it an instance of your class). As the static variables get shared in all instances; hence, they are not treated as thread-safe.

    Like that of static variables, static methods also have the same property, i.e., they do not belong to the instance of the class. They have one additional property, which is, they can not access all variables, but variables declared as static only. Also, they are restricted to invoking static class methods only. Static methods are prominently used in Java Wrapper classes and Utility classes.



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.