Course contentsShow
← Java
Lesson 365 of 2,8709. Static Members and Utility ClassesFree lesson

Calling static Methods from Instance Methods

How instance methods can freely call static methods, since static members are always available.

Calling static Methods from Instance Methods

What you'll learn: Instance methods can freely call static methods because static members belong to the class itself and are always available.


The Core Idea

You already know that static methods can't directly access instance members (because static code runs without a specific object). But the reverse works perfectly fine: instance methods can call static methods without any restrictions.

Why? Because static methods and fields exist at the class level—they're always present in memory, whether you have zero objects or a thousand. When an instance method runs, it has access to everything: both its own instance data (fields, other instance methods) and all the class-level static members.


How It Works

Inside any instance method, you can call a static method just like you'd call any other method:

public class Calculator {
    private int value;
    
    // Static utility method
    public static int add(int a, int b) {
        return a + b;
    }
    
    // Instance method that calls the static method
    public void addToValue(int amount) {
        value = add(value, amount);  // Calling static method directly
    }
}

You can call add directly by name because you're already inside the Calculator class. You could also write Calculator.add(value, amount) for clarity, but it's not required.


Why This Makes Sense

Think of static methods as shared tools in a toolbox. Every worker (instance) has access to those shared tools whenever they need them. The tools don't belong to any individual worker—they belong to the workshop itself.


Key Takeaway: Instance methods can freely call static methods because static members are always available at the class level, independent of any particular object.