When a class declares a static method m, the declaration of m hides any method m', where the signature of m is a subsignature of the signature of m' and the declaration of m' is both in the superclasses and superinterfaces of the declaring class and also would otherwise be accessible to code in the declaring class (The Java Language Specification, §8.4.8.2 "Hiding (by Class Methods)" [JLS 20052015]).
An instance method defined in a subclass overrides another instance method in the superclass when both have the same name, number and type of parameters, and return type.
...
Noncompliant Code Example
In this noncompliant code example, the programmer hides the static method rather than overriding it. Consequently, the code invokes the displayAccountStatus()
method of the superclass at two different call sites instead of invoking the superclass method at one call site and the subclass method at the other.
...
The methods inherited from the superclass can also be overloaded in a subclass. Overloaded methods are new methods unique to the subclass and neither hide nor override the superclass method [Java Tutorials 2008].
Technically, a private method cannot be hidden or overridden. There is no requirement that private methods with the same signature in the subclass and the superclass bear any relationship in terms of having the same return type or throws
clause, the necessary conditions for hiding [JLS 20052015]. Consequently, hiding cannot occur when private methods have different return types or throws
clauses.
...
Puzzle 48, "All I Get Is Static" | |||
...