What You'll Learn
You'll discover that @Override isn't just for overriding superclass methods—starting in Java 6, you can use it when implementing methods declared in interfaces.
Expanding @Override Beyond Inheritance
Before Java 6, @Override only worked when you were overriding a method from a parent class. If you implemented an interface method, adding @Override would cause a compiler error.
Java 6 changed this, recognizing that implementing an interface method is conceptually similar to overriding: you're providing a concrete implementation for an abstract contract. Now @Override verifies you're correctly implementing interface methods too.
Why This Matters
Using @Override on interface implementations gives you the same protection against typos and signature mistakes:
interface Drawable {
void render(int x, int y);
}
class Circle implements Drawable {
@Override // Valid since Java 6
public void render(int x, int y) {
System.out.println("Drawing circle at " + x + ", " + y);
}
}
If you accidentally misspell the method name or get the parameters wrong:
class Square implements Drawable {
@Override
public void render(int x, int y, int size) { // ERROR!
// Compiler catches that this doesn't match the interface
}
}
The compiler immediately tells you there's no interface method matching this signature—you're not actually implementing what you think you are.
Think of It As Contract Verification
Imagine signing a business contract. @Override is like having a lawyer verify your signature goes on the right document in the right place. It works whether you're signing as part of a family business (inheritance) or signing as an independent contractor (interface implementation).
Key Takeaway:
Since Java 6, @Override annotates both superclass method overrides and interface method implementations, helping catch signature mistakes in both scenarios.