Static vs. Instance
Methods
Learn to distinguish between methods that belong to the class and methods that belong to an object: when to use each, how they differ, and why it matters.
What Is a Method?
A method is a named block of code inside a class that performs a specific task. In Java, every method lives inside a class, but not every method behaves the same way.
The static Keyword
When you see the keyword static in a method signature, it means the method is associated with the class, not with any particular object created from it.
Instance Methods Need an Object
An instance method operates on the data stored inside a specific object. You must create an instance with new before you can call it.
The Core Rule
What static Methods Can and Cannot Do
static vs. instance: Side by Side
| static | instance | |
|---|---|---|
| Keyword | static in signature | No static keyword |
| Called on | The class | An object |
| Uses this? | No | Yes |
| Instance fields? | Cannot access | Can access |
| Typical use | Utility/helper | Object behavior |
| Example | Math.max(a, b) | str.toUpperCase() |
How to Decide: Step by Step
Example 1: Identifying Method Types
Example 2: Calling Each Type
Notice: Circle.areaFromRadius() uses the class name. c.getArea() uses the variable name that holds the object.
Example 3: main Is Always Static
Decision Flowchart
Real-World Java API Examples
Integer.parseInt("42")
Arrays.sort(arr)
Collections.max(list)
list.add("item")
scanner.nextInt()
obj.toString()
Under the Hood: Memory
Common Mistakes
Question 1 of 5
Which keyword in a method signature tells you the method belongs to the class rather than to an object?
Question 2 of 5
public class Counter {
private int count = 0;
public void increment() { count++; }
public static void reset(Counter c) { c.count = 0; }
}
Which statement about increment() and reset(Counter c) is correct?
Question 3 of 5
What happens if you try to access an instance variable directly inside a static method?
Question 4 of 5
Given String s = "hello"; which call is an instance method call?
Question 5 of 5
Why is Java's main method declared static?