Instance Methods vs Static Methods in Java
An instance method operates on a specific object — inside its body, it can freely read and modify that particular object's instance variables, and calling it requires an actual object to call it on. A static method belongs to the class itself, has no specific object associated with a call to it, and as a direct consequence, cannot access any instance variable or call any instance method directly — there's no particular object's data for it to reach for.
A static method can be called two ways that mean the same thing, ClassName.method() or through an instance reference, though the class-name form is the clearer, conventional one. An instance method, on the other hand, can only ever be called on an actual object, never on the class name alone.
Instance methods act on a specific object
They can read and modify that particular object's own instance variables directly.
Static methods act on the class
With no specific object involved, they cannot touch instance variables or call instance methods directly.
Calling an instance method
Requires an actual object, like myObject.doSomething().
Calling a static method
Conventionally through the class name, like ClassName.doSomething(), though calling it through an instance reference also works.
A static method can call another static method directly
But reaching an instance method or instance variable from inside a static one requires an actual object reference to do it through.
public class Circle { double radius; Circle(double radius) { this.radius = radius; } double area() { return Math.PI * radius * radius; } static double areaOf(double r) { return Math.PI * r * r; } public static void main(String[] args) { Circle c = new Circle(2); System.out.println("Instance method: " + c.area()); System.out.println("Static method: " + Circle.areaOf(2)); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.