Quick revision
The short answer
When a subclass declares a static method with the same signature as a static method in its parent, it hides the parent's method rather than overriding it. Static calls are resolved at compile time from the declared type of the expression, so with Parent p = new Child(), p.who() calls Parent's version, whatever the object really is. Calling a static method through an instance compiles only with a warning and misleads readers, and a static method may not hide an instance method, nor an instance method override a static one; both are compile errors.
What to remember
In this answer, we saw that a static method with the same signature in a subclass hides the parent's method instead of overriding it, because static calls are bound at compile time to the declared type, so Parent p = new Child(); p.who() runs Parent's version. Calling static methods through instances compiles with a warning and misleads readers, a static method cannot hide an instance method or the reverse, and fields, static or not, are hidden by declared type in the same way.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When a subclass declares a static method with the same signature as a static method in its parent, it hides the parent's method rather than overriding it. Static calls are resolved at compile time from the declared type of the expression, so with Parent p = new Child(), p.who() calls Parent's version, whatever the object really is. Calling a static method through an instance compiles only with a warning and misleads readers, and a static method may not hide an instance method, nor an instance method override a static one; both are compile errors.
Why this question is asked
Overriding is what makes polymorphism work, so it is natural to assume a static method in a subclass overrides the parent's one. It does not, and code that calls static methods through variables can then run a different method from the one the reader expects. Interviewers ask this to check that we know the difference between compile-time and runtime method selection, which also explains field hiding and several confusing compiler errors. In this answer, we will recap how overriding chooses a method, see what hiding does instead, reproduce the confusing call, go through the compile errors and look at fields, which behave the same way.
1A Quick Recap: How Overriding Chooses a Method
For an instance method, Java uses dynamic dispatch. The compiler checks that the method exists on the declared type of the variable, but the JVM picks the implementation at runtime from the actual class of the object. That is why Animal a = new Dog(); a.speak() runs Dog's speak().
A static method has no object. It belongs to the class, and a call to it is bound by the compiler to a specific class, emitted as an invokestatic instruction naming that class. There is nothing left for the JVM to decide at runtime, so there is nothing to override.
2Hiding Instead of Overriding
When Child declares a static method with the same signature as a static method in Parent, Child's method hides Parent's. Both methods exist, and which one runs depends only on which class the compiler binds the call to.
| Aspect | Instance method (override) | Static method (hide) |
|---|---|---|
| Chosen | at runtime, from the object's class | at compile time, from the declared type |
Parent p = new Child(); p.m() | Child's version | Parent's version |
@Override allowed | yes | no, compile error |
super.m() inside subclass | calls parent version | write Parent.m() instead |
| Called on a null reference | NullPointerException | works, the reference is ignored |
Notice the second line. The object is a Child, but the variable's declared type is Parent, so the compiler binds p.who() to Parent.who(). In fact the compiler does not even need the object: if p were null, p.who() would still print parent without a NullPointerException, because the reference is never used.
3Why Calling Static Methods Through Instances Misleads
Java allows p.who() for historical reasons, but javac warns about it with -Xlint:static (a static method should be qualified by type name), and IDEs flag it. The problem is that the code looks like a polymorphic call, and a reader reasonably expects Child's method to run.
The classic example in the JDK is Thread.sleep. Writing worker.sleep(1000) looks as if it pauses the worker thread, but sleep is static and always pauses the current thread. Writing Thread.sleep(1000) makes the truth visible. So the rule is simple: always call static methods through the class name.
4Mixing Static and Instance Methods Is a Compile Error
Java does not let a static method and an instance method share a signature across a class and its subclass, in either direction. Both cases are rejected by the compiler.
The reason is that the call p.run() must mean one thing. If one version were static and the other an instance method, the compiler could not decide whether to bind statically or dispatch dynamically. The last example shows a useful habit: putting @Override on a method that we believe overrides something makes the compiler tell us when it does not, including when the method is static. The exact wording of these messages varies a little between compilers, so check your version.
5Fields Are Hidden the Same Way
Fields are never dispatched dynamically, whether they are static or instance fields. A subclass field with the same name as a parent field hides it, and which one we read depends on the declared type of the expression.
So a Child object really has two label fields, and the declared type picks one. This is a good reason to keep fields private and access them through methods, which are dispatched dynamically if they are instance methods. Most style checkers flag hidden fields because they are almost always an accident.
6Follow-up questions
Can a static method be inherited?
Yes. If Child does not declare who(), then Child.who() compiles and calls Parent.who(). Static methods are inherited in the sense that they are accessible through the subclass name; they simply cannot be overridden. Static methods of interfaces are the exception: they are not inherited by implementing classes and must be called through the interface name.
Why does hiding matter for utility classes?
It mostly matters as a trap. If a subclass of a utility class redeclares a static method, callers that use the parent class name or a parent-typed variable keep calling the old version, so the redeclaration looks like it does nothing. Utility classes should be final with a private constructor so this cannot happen.
Is there any way to get polymorphic behaviour from static methods?
Not directly. If we need different behaviour per type, we use an instance method, perhaps on a singleton or a strategy object, or pass a function. Static methods are the right tool exactly when behaviour does not depend on the type of any object.
7Conclusion
In this answer, we saw that a static method with the same signature in a subclass hides the parent's method instead of overriding it, because static calls are bound at compile time to the declared type, so Parent p = new Child(); p.who() runs Parent's version. Calling static methods through instances compiles with a warning and misleads readers, a static method cannot hide an instance method or the reverse, and fields, static or not, are hidden by declared type in the same way.
Open with
A static method cannot be overridden, because there is no object involved, so nothing to dispatch on. The compiler binds a static call to a specific class and emits invokestatic.
Then, if they want more
If a subclass declares a static method with the same signature, it hides the parent's method: both exist, and which one runs depends only on the type the compiler sees. So with Parent p = new Child(), calling p.who() runs Parent's who, even though the object is a Child, while an instance method like p.name() would run Child's override.
It even works when p is null, because the reference is ignored. Calling a static method through an instance compiles, but with a lint warning, and it is misleading; the classic case is calling sleep on a Thread variable, which always sleeps the current thread. So I always call static methods by class name.
Mixing kinds is a compile error: a static method cannot hide an instance method, and an instance method cannot override a static one, because the call would be ambiguous between static binding and dynamic dispatch. Putting Override on a static method is also an error, which is a useful check.
Fields behave like static methods in this respect: both static and instance fields are hidden, not overridden, and chosen by the declared type, which is another reason to keep fields private.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Static methods cannot be overridden. What happens when a subclass declares a static...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/d43dd26271/