Skip to content
UniCircle
MediumConceptualPolymorphism

Rules for overriding and the @Override annotation

Question JAVA-POL-015

What rules must an overriding method follow in Java, and why should you always write @Override?

Show the explanation

An overriding method must:

  1. Have the same name and parameter types as the parent method.
  2. Have the same return type or a subtype (covariant return).
  3. Not be less accessible (a public method cannot become protected).
  4. Not throw new or broader checked exceptions (fewer or narrower is fine; unchecked is unrestricted).
  5. Not override a final, static or private method (static methods are hidden instead; private ones are not inherited).

@Override asks the compiler to check that you really are overriding. Without it, a small mistake silently creates an overload instead:

Java
class Point {
    int x, y;
    // Bug: equals(Point) overloads equals(Object); HashSet and List.contains will not call it
    public boolean equals(Point p) { return x == p.x && y == p.y; }
}
// With @Override on that method, the compiler reports an error immediately.

The correct signature is @Override public boolean equals(Object o), and it should always come with a matching hashCode().

Original UniCircle question. Last reviewed 22 Oct 2026.