• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

What’s Being Compared

Two forms of polymorphism in Java: Method Overloading (compile-time polymorphism) and Method Overriding (runtime polymorphism). Both allow multiple methods with the same name, but their mechanisms, purposes, and resolution times are fundamentally different.

The Core Tension

The distinction is when the method call is resolved: overloading at compile time (compiler picks the version based on static types), overriding at runtime (JVM picks the version based on the actual object type). This affects everything from performance (compile-time is faster) to flexibility (runtime enables polymorphic behavior).

Comparison

DimensionOverloading (Compile-Time)Overriding (Runtime)
Resolution timeCompile timeRuntime
Alternative nameStatic polymorphism, early bindingDynamic polymorphism, late binding
Parameter requirementMust differ (different type/count)Must be identical
Return typeCan differ freelyMust be same or covariant
Class requirementSame classDifferent classes (inheritance)
KeywordNone (automatic)@Override (optional, recommended)
Can be static?YesNo (static methods are hidden, not overridden)
Can be private?YesNo (private methods are not inherited)
Can be final?YesNo (final methods cannot be overridden)
PerformanceFaster (resolved at compile time)Slightly slower (vtable lookup)
Use caseAPI convenience, type flexibilityPolymorphic behavior, substitution

When to Choose Overloading

  • You want a convenient API where similar operations accept different types (print(int), print(String), print(boolean))
  • The behavior variation is based on input types, not object type
  • Performance matters and the variation is known at compile time

When to Choose Overriding

  • You need polymorphic behavior — code written against a base type should work with any subtype
  • Different subclasses need different implementations of the same contract
  • You’re designing an interface or abstract class that subclasses will implement

The Insight

Overloading and overriding serve completely different purposes despite both involving “same method name.” Overloading is about API convenience — giving the developer a clean API that works with multiple input types. Overriding is about behavioral substitution — enabling the Liskov Substitution Principle where subtypes can replace their parent types. The only thing they share is the method name reuse, and they can coexist: a method can be both overloaded (in its class) and overridden (by subclasses).

Connections