What is method overloading and method overriding in Java?
Method overloading and method overriding are both forms of polymorphism but operate at different phases and on different axes.
**Method overloading** (compile-time / static polymorphism): Multiple methods in the same class share the same name but differ in their parameter list — number of parameters, parameter types, or both. The compiler determines at compile time which overload to call based on the argument types and count. Return type alone is not sufficient to distinguish overloads. Example: `print(int x)`, `print(double x)`, `print(String s)` in the same class.
**Method overriding** (runtime / dynamic polymorphism): A subclass provides its own implementation of a method that is already defined in a superclass, keeping the same method signature (name + parameter list + return type, where the return type may be a covariant subtype since Java 5). The JVM determines at runtime which implementation to call based on the actual type of the object, not the declared type of the reference. This is the mechanism that enables polymorphic behavior.
Rules for overriding: - The method signature must match. - Access modifier cannot be more restrictive than the parent's. - Cannot override `static`, `final`, or `private` methods. - The `@Override` annotation should be used — it causes a compile error if the signature doesn't match, preventing silent overload-instead-of-override bugs. - Overriding method can throw narrower (or no) checked exceptions, but not broader ones.
The key conceptual distinction: overloading is resolved by the compiler based on static type; overriding is resolved by the JVM at runtime based on the actual object type. This is why overloading is called static polymorphism and overriding is dynamic polymorphism.
| Aspect | Overloading | Overriding |
|---|---|---|
| Also called | Static / compile-time polymorphism | Dynamic / runtime polymorphism |
| Where defined | Same class | Subclass (of superclass/interface) |
| Signature | Different parameter list | Same parameter list and name |
| Return type | Can differ | Must match (covariant return allowed) |
| Resolved by | Compiler | JVM at runtime |
| @Override annotation | N/A | Recommended — prevents silent bugs |
Correctly distinguishes compile-time vs runtime resolution and gives a concrete example of each.
Also covers the overriding rules (access modifier, exceptions, covariant return), the @Override annotation, and explains why static/private/final methods cannot be overridden.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment