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.

🌐
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 - In Java, the static modifier means something is directly related to a class: if a field is static, then it belongs to the class; if a method is static, then it belongs to the class.
🌐
Tutorialspoint
tutorialspoint.com › java › java_nonaccess_modifiers.htm
Java - Non Access Modifiers
The final modifier for finalizing ... volatile modifiers, which are used for threads. The static keyword is used to create variables that will exist independently of any instances created for the class....
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-final-vs-static-access-modifier
Java - Final vs Static Access Modifier - GeeksforGeeks
July 23, 2025 - Static access modifier is an access modifier that is applicable for methods and variables but not for classes. 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 ...
🌐
W3Schools
w3schools.com › java › java_modifiers.asp
Java Modifiers
Java Examples Java Compiler Java Exercises Java Quiz Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The public keyword is an access modifier, meaning that it is used to set the access level for classes, attributes, methods and constructors. ... In the example below, the class has one public attribute and one private attribute. ... class Person { public String name = "John"; // Public - accessible everywhere private int age = 30; // Private - only accessible inside this class } public class Main { public static void main(String[] args) { Person p = new Person(); System.out.println(p.name); // Works fine System.out.println(p.age); // Error: age has private access in Person } }
🌐
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.
🌐
LabEx
labex.io › questions › how-to-use-static-modifier-in-java-178543
How to use static modifier in Java | LabEx
The static modifier in Java is a keyword used to declare a class member (variable or method) as belonging to the class itself, rather than to any specific instance of the class.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › static-keyword-java
static Keyword in Java - GeeksforGeeks
No object creation is needed to access static members; use the class name directly. Static methods and variables can’t access non-static members directly. Static methods can’t be overridden because they belong to the class, not instances. The static keyword can be applied to four main components:
Published   May 25, 2017
🌐
promineo-tech
promineotech.com › post › understanding-java-the-non-access-modifier-static
Understanding Java: The Non-Access Modifier: Static
March 3, 2020 - The static modifier makes a member (variables or methods) of a class independent of the objects of the class and is used when we are defining properties that are common to all objects in the class.
🌐
Medium
medium.com › @gauravshah97 › modifiers-in-java-4b2cc8597424
Modifiers in Java
June 22, 2024 - ■ Final method: A final method defined in a base class can’t be overridden by a derived class. static modifier: The non-access modifier static can be applied to the declarations of variables, methods, classes, and interfaces.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › classvars.html
Understanding Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
In the case of the Bicycle class, the instance variables are cadence, gear, and speed. Each Bicycle object has its own values for these variables, stored in different memory locations. Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier.
🌐
Sarthaks eConnect
sarthaks.com › 3492047 › what-is-the-static-modifier-in-java
What is the static modifier in Java? - Sarthaks eConnect | Largest Online Education Community
LIVE Course for free · The static modifier in Java is a non-access modifier that is used to create class-level variables and methods. When a variable or method is declared as static, it becomes associated with the class itself rather than with ...
🌐
Pdx
stemrobotics.cs.pdx.edu › node › 4562.html
Static Modifier | STEMRobotics
What if we would like to have a ... level? We can do that with the static modifier. Marking a variable as static means there is only one copy of the variable for all class instances....
🌐
Quora
quora.com › What-is-a-static-modifier
What is a static modifier? - Quora
Answer: In an OOP language like Java, a static modifier used for members of a class means that these members qualified with a static modifier do not need an object of the class you be accessed and can be accessed using the class name only.
🌐
Coderanch
coderanch.com › t › 448534 › java › static-modifier
when should we use static modifier (Java in General forum at Coderanch)
I make my JTextArea static, which ensures that I can write to the JTextArea from both static and nonstatic methods in other parts of the application. When I no longer need to do diagnostics, I will remove the static modifer, or maybe just remove the JTextARea and all the statements that write to it. ... Here is one other reason.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › reflect › Modifier.html
Modifier (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... The Modifier class provides static methods and constants to decode class and member access modifiers. The sets of modifiers are represented as integers with distinct bit positions representing different modifiers.
🌐
Baeldung
baeldung.com › home › java › core java › a guide to the static keyword in java
A Guide to the Static Keyword in Java | Baeldung
January 8, 2024 - In Java, when we declare a field static, exactly a single copy of that field is created and shared among all instances of that class.
🌐
Reddit
reddit.com › r/learnprogramming › what does the "static" keyword mean in java and why is the main method required to have it?
r/learnprogramming on Reddit: What does the "static" keyword mean in java and why is the main method required to have it?
June 19, 2022 -

I am new to object oriented programming, and I was following a tutorial in which they mentioned that in java, the keyword static means that the particular member belongs to a type itself, rather than to an instance of that type. I have read this definition a lot of times across the internet but this is complex for me to understand, can anyone tell me in simple language what it means? Thanks!

🌐
GeeksforGeeks
geeksforgeeks.org › java › static-method-in-java-with-examples
Static Method in Java With Examples - GeeksforGeeks
In Java, the static keyword is used to create methods that belongs to the class rather than any specific instance of the class.
Published   May 2, 2025