Why can't static or private methods be overridden?

8 minadvancedstaticprivatepolymorphism

Quick Answer

Overriding relies on dynamic dispatch through the object's runtime type via the vtable. Static methods belong to the class, not an instance, and are resolved at compile time by the reference's declared type, so a subclass can only 'hide' a static method with the same signature, not override it. Private methods aren't visible outside their declaring class at all, so subclasses can't even see them to override.

Detailed Answer

Overriding requires dynamic dispatch: the JVM looks up which implementation to run based on the object's actual runtime type. That mechanism only applies to instance methods.

Static methods belong to the class itself, not to any instance, and are bound at compile time based on the declared (static) type of the reference — this is called method hiding, not overriding:

class A { static void greet() { System.out.println("A"); } }
class B extends A { static void greet() { System.out.println("B"); } }

A ref = new B();
ref.greet(); // prints "A" — resolved by ref's declared type (A), not the object's actual type

Private methods aren't inherited in any visible sense — a subclass can't even see, let alone override, a superclass's private method. If a subclass declares a method with the same name/signature, it's simply an unrelated new method local to the subclass, not an override; calling it from within the subclass just calls that new method, and any call from within the superclass still calls the superclass's own private method.

Both cases boil down to the same idea: overriding needs a virtual method table entry resolved per-object at runtime, and neither static (class-bound) nor private (not inherited/visible) methods participate in that mechanism.