Static Method vs Instance Method in Java
Last Updated :
11 Nov, 2025
In Java, methods define the behavior of classes and objects. Understanding the difference between static methods and instance methods is essential for writing clean and efficient code.
What is a Static Method?
A static method belongs to the class rather than any specific object.
- Can be called without creating an instance of the class.
- Since static methods are not object-specific, they can access only static members (data and methods), and cannot access non-static members.
Java
import java.io.*;
class Geeks {
// static method
public static void greet() {
System.out.println("Hello Geek!");
}
public static void main(String[] args) {
// calling the method directily
greet();
// using the class name
Geeks.greet();
}
}
OutputHello Geek!
Hello Geek!
Explanation: The above example shows a static method greet() inside the Geeks class, static methods can be called without creating an object. In the main method, we are not creating an object of Geeks class we are calling the method directly by the class name which is Geeks and then we are printing the output.
What is an Instance Method?
An Instance method belongs to an object.
- Need to create an instance of the class to call.
- Can access instance variables, other instance methods, and static members of the class.
- Have access to
this reference, which points to the current object.
Java
import java.io.*;
class Test {
String n = "";
// Instance method
public void test(String n) {
this.n = n;
}
}
class Geeks {
public static void main(String[] args) {
// create an instance of the class
Test t = new Test();
// calling an instance method in the class 'Geeks'
t.test("GeeksforGeeks");
System.out.println(t.n);
}
}
Explanation: The above example shows how to use an instance method in Java. We are creating an object of the Test class and calling the test method to set a value and then we are printing the output.
Difference Between Static Method and Instance Method
The following table lists the major differences between the static methods and the instance methods in Java.
Features | Static method | Instance method |
|---|
Definition | Created using the static keyword and retrieved without creating an object. | Requires an object of its class to be invoked. |
|---|
Access | Access only static variables and methods. | Can access both static and instance members. |
|---|
this keyword
| Cannot use the this keyword within static methods. | Can use the this keyword to refer to the current object. |
|---|
Override | Does not support runtime polymorphism | Supports runtime polymorphism |
|---|
Memory Allocation | Loaded once per class | Each object has its own copy |
|---|
Which statement correctly describes a static method in Java?
-
It always requires an object to be called
-
It belongs to the class, not objects
-
It can access all instance variables
-
It supports runtime polymorphism
Explanation:
Static methods are class-level methods and do not depend on object creation.
Which of the following can an instance method access?
-
-
-
Both static and instance members
-
Explanation:
Instance methods can access all members of the class—static and instance.
How many times is a static method loaded into memory?
Explanation:
Static methods are loaded once when the class is loaded into memory.
Quiz Completed Successfully
Your Score : 2/3
Accuracy : 0%
Login to View Explanation
1/3
1/3
< Previous
Next >
Explore
Java Basics
OOP & Interfaces
Collections
Exception Handling
Java Advanced
Practice Java