Why this matters
- Nearly every framework you will use — Spring, JDBC, the Collections Framework — works because of run-time overriding.
- The "which method runs" puzzle is a staple interview question, and the answer requires separating the two mechanisms cleanly.
- Static method hiding catches almost everyone once, and knowing it exists saves an afternoon.
Compile-time: overloading
Same name, different parameter lists. The compiler decides, using only the declared types at the call site.
The object is a String, but the variable is declared Object, and that is all the compiler looks
at. Overloading is never influenced by run-time type.
Run-time: overriding
Same signature, redefined in a subclass. The JVM decides, using the actual object.
Decided before the program runs.
This is dynamic dispatch. The JVM consults the object's class to find the right method body — conceptually a lookup in a per-class method table. It is the mechanism that makes abstraction useful at run time.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- The two side by side
- Rules for a valid override
- Static method hiding
- Upcasting and downcasting
- Common misreadings
Test yourself
Answer these before moving on — recall is what makes it stick.