The 30 second answer
Overloading is several methods with the same name in one class but different parameter lists; the compiler picks one at compile time from the argument types. Overriding is a subclass giving its own version of an inherited instance method with the same signature; the JVM picks it at runtime from the object's actual class. Overriding can't reduce visibility or throw broader checked exceptions, and I always add @Override so the compiler catches mistakes. Static methods are hidden, not overridden.
<!-- level: 1 --> <!-- must_know: true -->
| Overloading | Overriding | |
|---|---|---|
| Where | Same class (or inherited) | Subclass of the declaring class |
| Signature | Same name, different parameters | Same name and parameters |
| Return type | Can differ | Same or a subtype (covariant) |
| Chosen | At compile time, by argument types | At runtime, by the object's class |
| Applies to | Any method, constructors too | Instance methods only |
Rules from the Java Language Specification and tutorial:
- An overriding method cannot have weaker access (a
publicmethod can't becomeprotected) and cannot declare broader checked exceptions. staticmethods are hidden, not overridden: which one runs depends on the reference type.privateandfinalmethods cannot be overridden.@Overridemakes the compiler fail if the method doesn't actually override anything, which catches typos likeequals(Employee other)instead ofequals(Object other).