You can think of a 'static' method or field as if it were declared outside the class definition. In other words

  1. There is only one 'copy' of a static field/method.
  2. Static fields/methods cannot access non-static fields/methods.

There are several instances where you would want to make something static.

The canonical example for a field is to make a static integer field which keeps a count across all instances (objects) of a class. Additionally, singleton objects, for example, also typically employ the static modifier.

Similarly, static methods can be used to perform 'utility' jobs for which all the required dependencies are passed in as parameters to the method - you cannot reference the 'this' keyword inside of a static method.

In C#, you can also have static classes which, as you might guess, contain only static members:

public static class MyContainer
{
    private static int _myStatic;

    public static void PrintMe(string someString)
    {
        Console.Out.WriteLine(someString);
        _myStatic++;
    }

    public static int PrintedInstances()
    {
        return _myStatic;
    }
}
Answer from Alex on Stack Overflow
Top answer
1 of 7
22

You can think of a 'static' method or field as if it were declared outside the class definition. In other words

  1. There is only one 'copy' of a static field/method.
  2. Static fields/methods cannot access non-static fields/methods.

There are several instances where you would want to make something static.

The canonical example for a field is to make a static integer field which keeps a count across all instances (objects) of a class. Additionally, singleton objects, for example, also typically employ the static modifier.

Similarly, static methods can be used to perform 'utility' jobs for which all the required dependencies are passed in as parameters to the method - you cannot reference the 'this' keyword inside of a static method.

In C#, you can also have static classes which, as you might guess, contain only static members:

public static class MyContainer
{
    private static int _myStatic;

    public static void PrintMe(string someString)
    {
        Console.Out.WriteLine(someString);
        _myStatic++;
    }

    public static int PrintedInstances()
    {
        return _myStatic;
    }
}
2 of 7
8

Static uses less memory since it exists only once per Classloader.

To have methods static may save some time, beacuse you do not have to create an object first so you can call a function. You can/should use static methods when they stand pretty much on their own (ie. Math.abs(X) - there really is no object the function needs.) Basically its a convenience thing (at least as far as I see it - others might and will disagree :P)

Static fields should really be used with caution. There are quite a few patterns that need static fields... but the basics first:

a static field exists only once. So if you have a simple class (kinda pseudocode):

class Simple {
 static int a;
 int b;
}

and now you make objects with:

Simple myA = new Simple();
Simple myB = new Simple();
myA.a = 1;
myA.b = 2;
myB.a = 3;
myB.b = 4;
System.out.println(myA.a + myA.b + myB.a + myB.b);

you will get 3234 - because by setting myB.a you actually overwrite myA.a as well because a is static. It exists in one place in memory.

You normally want to avoid this because really weird things might happen. But if you google for example for Factory Pattern you will see that there are actually quite useful uses for this behaviour.

Hope that clears it up a little.

🌐
Tutorialspoint
tutorialspoint.com › java › java_nonaccess_modifiers.htm
Java - Non Access Modifiers
With variables, the final modifier ... following are examples of declaring constants: public static final int BOXWIDTH = 6; static final String TITLE = "Manager"; public void changeValue() { value = 12; // will give an error } }...
🌐
GeeksforGeeks
geeksforgeeks.org › java › static-method-in-java-with-examples
Static Method in Java With Examples - GeeksforGeeks
Non-static data members or non-static methods cannot be used by static methods, and static methods cannot call non-static methods directly. In a static environment, this and super are not allowed to be used.
Published   May 2, 2025
🌐
Albertprofe
albertprofe.dev › javase › se-concepts-static.html
Java SE: static modifier – albertprofe wiki
In Java, the static modifier is used to indicate that a class or class member belongs to the class itself, rather than to an instance of the class. In other words, the static modifier indicates that the class or class member is associated with the class as a whole, rather than with a specific instance of the class. Classical use and basic example of static method, we call within the class our static method just using the name of the method printArea():
🌐
CodeGym
codegym.cc › java blog › keywords in java › 10 things you need to know about the static modifier in j...
10 things you need to know about the static modifier in Java
October 11, 2023 - Another example is the declaration of our own Comparator, such as an age comparator (AgeComparator) in the Employee class. The static modifier can also be specified in a static block, better known as a "static initialization block", which is executed when the class is loaded. If you don't declare such a block, Java collects all static fields into a single list and initializes them when the class is loaded.
🌐
LabEx
labex.io › questions › how-to-use-static-modifier-in-java-178543
How to use static modifier in Java | LabEx
Learn how to use the static modifier in Java for class variables and methods to enhance memory efficiency and code flexibility.
🌐
Pdx
stemrobotics.cs.pdx.edu › node › 4562.html
Static Modifier | STEMRobotics
The example uses a static variable to count how many instances of MyClass are created. We increment globalCount in the class constructor. This would make globalCount = 2 but to demonstrate static variable access, we directly increment globalCount to 3. We can do this since globalCount has public ...
🌐
Javapapers
javapapers.com › core-java › explain-the-java-static-modifier
Java Static - Javapapers
Java Static Variables Java instance variables are given separate memory for storage. If there is a need for a variable to be common to all the objects of a single java class, then the static modifier should be used in the variable declaration. Any java object that belongs to that class can modify its static […]
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › reflect › Modifier.html
Modifier (Java Platform SE 7 )
For example: public final synchronized strictfp The modifier names are returned in an order consistent with the suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of The Java™ Language Specification. The full modifier ordering used by this method is: public protected private abstract static final transient volatile synchronized native strictfp interface The interface modifier discussed in this class is not a true modifier in the Java language and it appears after all other modifiers listed by this method.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-final-vs-static-access-modifier
Java - Final vs Static Access Modifier - GeeksforGeeks
July 23, 2025 - We can not declare top-level class with a static modifier but we can declare the inner class as static (such types of inner classes are known as static nested classes). In the case of instance variable for every object, a separate copy will be created but in the case of static variable, a single copy will be created at class level and shared by every object of that class. ... // Java Program to Illustrate Static Access Modifier // Importing required classes import java.io.*; import java.util.*; // Main class class Geeks { // Creating a static variable and // initializing a custom value static
🌐
W3Schools
w3schools.com › java › java_modifiers.asp
Java Modifiers
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › classvars.html
Understanding Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
If the value of the constant in the outside world changes (for example, if it is legislated that pi actually should be 3.975), you will need to recompile any classes that use this constant to get the current value. After all the modifications made in this section, the Bicycle class is now: public class Bicycle { private int cadence; private int gear; private int speed; private int id; private static int numberOfBicycles = 0; public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; id = ++numberOfBicycles; } public int getID
🌐
Coderanch
coderanch.com › t › 448534 › java › static-modifier
when should we use static modifier (Java in General forum at Coderanch)
David Newton wrote Isn't static stuff covered in the SCJP? David, your comments really kicked me to go through the book again... And Muhammad Ali Khojaye, thanks for your important suggestion · Another important point to consider when you make method static is that you must make sure there is no chance you’ll want it to behave polymorphically. ... Here is just one example.
🌐
DataCamp
datacamp.com › doc › java › modifiers
Java Modifiers
In this example, CONSTANT is a static and final variable, meaning it belongs to the class and cannot be changed. Use Access Modifiers Wisely: Restrict access as much as possible to protect your data.
🌐
Medium
medium.com › @gauravshah97 › modifiers-in-java-4b2cc8597424
Modifiers in Java
June 22, 2024 - But you can define a class and an interface as a static member of another class. synchronized: A synchronized method can’t be accessed by multiple threads concurrently. — The synchronized modifier can’t be applied to classes, interfaces, or variables with this modifier.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › reflect › Modifier.html
Modifier (Java Platform SE 8 )
October 20, 2025 - For example: public final synchronized strictfp The modifier names are returned in an order consistent with the suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of The Java™ Language Specification. The full modifier ordering used by this method is: public protected private abstract static final transient volatile synchronized native strictfp interface The interface modifier discussed in this class is not a true modifier in the Java language and it appears after all other modifiers listed by this method.
🌐
W3Schools
w3schools.com › java › ref_keyword_static.asp
Java static Keyword
The static keyword is a non-access modifier used for methods and attributes. Static methods/attributes can be accessed without creating an object of a class. Read more about modifiers in our Java Modifiers Tutorial.
🌐
DEV Community
dev.to › satyam_gupta_0d1ff2152dcc › java-non-access-modifiers-explained-a-deep-dive-into-static-final-abstract-more-2bba
Java Non-Access Modifiers Explained: A Deep Dive into static, final, abstract & more - DEV Community
October 17, 2025 - By convention, final variable names are in UPPER_SNAKE_CASE. java public class Constants { // A static final variable - a class-level constant public static final double PI = 3.14159; public static final String COMPANY_NAME = "CoderCrafter Inc."; // ...
🌐
Javatpoint
javatpoint.com › static-keyword-in-java
static keyword in Java - javatpoint
static keyword. Let's see what is static variable,method and block in java and what is its advantage and usage.
🌐
Medium
medium.com › @AlexanderObregon › beginners-guide-to-java-modifiers-d86a6b9d5dd9
Java Modifiers Explained For Beginners | Medium
February 29, 2024 - Non-Access Modifiers: Beyond controlling access, Java allows you to modify the behavior of classes, methods, and variables using non-access modifiers. These include keywords like static, final, abstract, synchronized, and volatile, each serving different purposes such as defining class methods ...