Course contentsShow
← Java
Lesson 422 of 2,87010. Inheritance FundamentalsFree lesson

static Methods Cannot Be Overridden

Understand that static methods are hidden, not overridden, and why static binding applies to them.

static Methods Cannot Be Overridden

You'll learn why static methods behave fundamentally differently from instance methods when it comes to overriding.

The Core Idea

When you declare a method as static, it belongs to the class itself, not to any instance. Because overriding is about replacing behavior in a specific object (an instance), and static methods aren't tied to instances, they simply cannot be overridden. Instead, if you declare a static method in a subclass with the same signature as one in the superclass, you're hiding it, not overriding it.

Static Binding vs Dynamic Binding

Instance methods use dynamic binding (also called runtime polymorphism): Java decides which version of an overridden method to call based on the actual object type at runtime.

static methods use static binding (compile-time binding): Java decides which static method to call based on the reference type at compile time, not the actual object.

Why This Matters

class Parent {
    static void display() {
        System.out.println("Parent static method");
    }
}

class Child extends Parent {
    static void display() {  // This HIDES, not overrides
        System.out.println("Child static method");
    }
}
Parent ref = new Child();
ref.display();  // Prints "Parent static method"

Even though ref points to a Child object, the Parent version runs because the reference type is Parent. The method is chosen at compile time based on the reference, not the object.

Analogy

Think of static methods like a family recipe book that belongs to the family name itself. Each branch of the family can have their own version, but which recipe you see depends on which family's book you open, not which family member is standing there.

Key Takeaway: static methods cannot be overridden—they can only be hidden. Java uses the reference type (not the object type) to determine which static method to call, making @Override invalid for static methods.