One rule-of-thumb: ask yourself "Does it make sense to call this method, even if no object has been constructed yet?" If so, it should definitely be static.

So in a class Car you might have a method:

double convertMpgToKpl(double mpg)

...which would be static, because one might want to know what 35mpg converts to, even if nobody has ever built a Car. But this method (which sets the efficiency of one particular Car):

void setMileage(double mpg)

...can't be static since it's inconceivable to call the method before any Car has been constructed.

(By the way, the converse isn't always true: you might sometimes have a method which involves two Car objects, and still want it to be static. E.g.:

Car theMoreEfficientOf(Car c1, Car c2)

Although this could be converted to a non-static version, some would argue that since there isn't a "privileged" choice of which Car is more important, you shouldn't force a caller to choose one Car as the object you'll invoke the method on. This situation accounts for a fairly small fraction of all static methods, though.

Answer from not-just-yeti on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › static-method-in-java-with-examples
Static Method in Java With Examples - GeeksforGeeks
A static method in Java is associated with the class, not with any object or instance.
Published   1 week ago
Top answer
1 of 16
1671

One rule-of-thumb: ask yourself "Does it make sense to call this method, even if no object has been constructed yet?" If so, it should definitely be static.

So in a class Car you might have a method:

double convertMpgToKpl(double mpg)

...which would be static, because one might want to know what 35mpg converts to, even if nobody has ever built a Car. But this method (which sets the efficiency of one particular Car):

void setMileage(double mpg)

...can't be static since it's inconceivable to call the method before any Car has been constructed.

(By the way, the converse isn't always true: you might sometimes have a method which involves two Car objects, and still want it to be static. E.g.:

Car theMoreEfficientOf(Car c1, Car c2)

Although this could be converted to a non-static version, some would argue that since there isn't a "privileged" choice of which Car is more important, you shouldn't force a caller to choose one Car as the object you'll invoke the method on. This situation accounts for a fairly small fraction of all static methods, though.

2 of 16
614

Define static methods in the following scenarios only:

  1. If you are writing utility classes and they are not supposed to be changed.
  2. If the method is not using any instance variable.
  3. If any operation is not dependent on instance creation.
  4. If there is some code that can easily be shared by all the instance methods, extract that code into a static method.
  5. If you are sure that the definition of the method will never be changed or overridden. As static methods can not be overridden.
Discussions

Static method definition in Java
means I can just use it without creating an object? Yes, And you don't have to define the object, but to do that you need to do an import of it. For example, flyway has a static method called configure, if I want to just call configure() and not Flyway.configure() I need to import it: import static org.flywaydb.core.Flyway.configure; More on reddit.com
🌐 r/learnjava
6
8
April 13, 2022
Can a static method be overridden in Java?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
15
1
October 22, 2024
Can a static method be overridden in Java?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
11
11
October 19, 2024
Why does Java prohibit static fields in inner classes?
An inner class is associated with an instance, so it can't have any static members. Unless your inner class is static (public static class Inner), in which case you can use static members. But then you won't be able to access Outer's non-static properties. It's basically one or the other. Either your inner class is static, and then it can be referenced outside the outer class and use static members. Or it's non-static, in which case it's bound to an instance of the outer class. Edit: useful link: http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html More on reddit.com
🌐 r/java
65
18
January 10, 2014
People also ask

When should you use static in Java?
Use static when you want a method or variable to be shared across all instances of a class or if it doesn’t depend on instance-specific data.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › software development
Static vs Non-Static Java Overview | Pluralsight
What is the difference between static and non-static in Java?
The main difference is that static elements are shared across all instances of a class and belong to the class itself, while non-static elements are tied to specific objects.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › software development
Static vs Non-Static Java Overview | Pluralsight
What are use cases for non-static variables and methods?
Non-static variables and methods are useful when behavior or data needs to be different per object—for example, when each object should maintain its own state.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › software development
Static vs Non-Static Java Overview | Pluralsight
🌐
Scaler
scaler.com › home › topics › java › static method in java with examples
Static Method in Java With Examples - Scaler Topics
April 1, 2024 - The static methods are class methods that don't belong to instances of the class. They are designed to be shared among all instances of the same class and are accessed by the class name of the particular class.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › what is static method in java with examples
What is Static Method in Java with Examples
September 12, 2024 - ... In Java, a static method is a method that belongs to the class, rather than an instance of the class. Static methods are accessed through the class name, rather than an object of the class.
🌐
DataCamp
datacamp.com › doc › java › static
static Keyword in Java: Usage & Examples
Static variables are shared among all instances of a class. They are also known as class variables. ... Static methods can be called without creating an instance of 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.
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › static method definition in java
r/learnjava on Reddit: Static method definition in Java
April 13, 2022 -

So I searched up the definition of static

“In Java, a static method is a method that belongs to a class rather than an instance of a class. The method is accessible to every instance of a class, but methods defined in an instance are only able to be accessed by that object of a class.” -Techopedia This definition almost gave me a stroke 💀

I was wondering if it just means that creating a static method (just attaching the keyword static to a method declaration) means I can just use it without creating an object? And so when I want to use the method I don’t have to write like Object.methodName() I can just call it/use it directly like methodName()??? Similar to how we’ve been calling and using methods in procedural style programming where you just have the static main method and then was able to casually call any other methods you’ve created down below?

Is that all there is the static keyword? A method you can use without having to create an object and not needing to write Object.methodName() and just call it directly like methodName()???

I’ve trying to wrap my head and revisit this term.

🌐
GeeksforGeeks
geeksforgeeks.org › java › static-methods-vs-instance-methods-in-java
Static Method vs Instance Method in Java - GeeksforGeeks
2 weeks ago - A static method belongs to the class rather than any specific object, allowing it to be called without creating an instance. It is commonly used for operations that do not depend on object state.
🌐
freeCodeCamp
freecodecamp.org › news › static-variables-in-java
Static Variables in Java – Why and How to Use Static Methods
March 7, 2023 - As you can see above, we declared ... static in Java programming, it means that the variable belongs to the class itself rather than to any specific instance of the class....
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › software development
Static vs Non-Static Java Overview | Pluralsight
May 19, 2025 - In Java, different elements can be static: Variables – A single shared variable for all instances of a class. Methods – Methods you can call without creating an object.
🌐
Study.com
study.com › computer programming › programming languages
Static vs. Non-Static Methods in Java - Lesson | Study.com
December 8, 2017 - To create a static method in Java, you prefix the key word 'static' before the name of the method. A static method belongs to the class, and you do not have to create an instance of the class to access the static method.
🌐
Baeldung
baeldung.com › home › java › core java › use cases for static methods in java
Use Cases for Static Methods in Java | Baeldung
January 8, 2024 - Static methods are common to most object-oriented programming languages, including Java. What differentiates static from instance methods is that they have no object that owns them.
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit6-Writing-Classes › topic-6-7-static-vars-methods.html
6.7. Static Variables and Methods — CS Java
Static methods only have access to other static variables and static methods (unless the static method creates an object through which to access instance variables and methods). Static methods cannot access or change the values of instance variables or use the “this” reference (since there is no calling object for them), and static methods cannot call non-static methods.
🌐
Educative
educative.io › blog › static-method-in-java
A Guide on Static Methods in Java With Examples
January 22, 2024 - The static methods in Java are considered class-level methods. They are not attached to a specific object of the class. They can be called using the class name or object name from anywhere in the program as per access permission.
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-static-and-non-static-method-in-java
Difference between static and non-static method in Java - GeeksforGeeks
June 30, 2023 - A static method is a method that belongs to a class, but it does not belong to an instance of that class and this method can be called without the instance or object of that class.
🌐
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 this tutorial, we’ll explore the static keyword of the Java language in detail. The static keyword means that a member – like a field or method – belongs to the class itself, rather than to any specific instance of that class.
🌐
Medium
medium.com › @mawunachristinabright › static-vs-public-in-java-2f7ce0941637
Static vs public in java. In Java, a static method is a method… | by Christina Bright | Medium
July 24, 2023 - In Java, a static method is a method that belongs to the class itself rather than to any specific instance (object) of the class.Static methods can be called without creating objects.This means that you can call a static method using the class ...
🌐
Edureka
edureka.co › blog › java-static-method
Java Static Method | Static Keyword In Java | Edureka
March 1, 2023 - The method is accessible to every instance of a class, but methods defined in an instance are only able to be accessed by that member of a class. ... //Java Program to demonstrate the use of a static method.
🌐
Scientech Easy
scientecheasy.com › home › blog › static method in java (with examples)
Static Method in Java (with Examples) - Scientech Easy
January 18, 2026 - To declare a static method in Java program, use the static keyword before the method’s return type. The term static means that the method belongs to the class rather than to any specific instance (object) of the class.