100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Method Overloading vs Overriding

Method overloading vs overriding — compile-time vs runtime resolution, signature rules and dynamic dispatch — explained with Java examples and Q&A.

mediumQ8 of 226 in Object Oriented Programming Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

Method overloading is defining multiple methods with the same name but different parameter lists within a class, resolved at compile time, while method overriding is a subclass providing its own implementation of a method already defined in its superclass, resolved at runtime.

Overloading is compile-time polymorphism: the compiler picks the matching method based on argument types, count, or order at the call site. Overriding is runtime polymorphism: the actual object type determines which implementation runs via dynamic dispatch, even when called through a base-type reference. Overriding requires the same method signature and return type (or covariant), while overloading requires a different signature. Overriding also enforces access-modifier rules (cannot reduce visibility) and requires an is-a relationship between classes.

  • Overloading: convenient API variations for the same operation
  • Overriding: enables runtime polymorphism and extensibility
  • Together: flexible, readable APIs that adapt behavior by type
  • Clear separation of compile-time vs runtime resolution

AI Mentor Explanation

Overloading is a single "throw" word used differently depending on what you hand the fielder — throw(ball), throw(ball, target) — the coach picks the right drill just from what’s given, before play even starts. Overriding is a bowler subclass replacing the base "bowl" technique entirely: a spinner’s bowl() behaves nothing like a pacer’s bowl(), decided only once play begins and the actual bowler is known. One is chosen ahead of time by the inputs; the other is chosen live by who is actually bowling.

Step-by-Step Explanation

  1. Step 1

    Overloading: same name, different signature

    Define multiple methods in one class differing in parameter type, count, or order.

  2. Step 2

    Overloading resolved at compile time

    The compiler matches the call to a method based on the arguments passed.

  3. Step 3

    Overriding: same signature, subclass redefines

    A subclass provides its own body for a method already declared in the superclass.

  4. Step 4

    Overriding resolved at runtime

    Dynamic dispatch picks the implementation based on the object’s actual class.

What Interviewer Expects

  • Correct compile-time vs runtime distinction
  • Signature requirements for each (different vs identical)
  • Awareness that static methods cannot be truly overridden (only hidden)
  • A code example distinguishing both clearly

Common Mistakes

  • Saying both are resolved at the same time
  • Confusing return-type-only differences as valid overloading
  • Thinking private or static methods can be overridden
  • Not mentioning the access-modifier restriction on overriding

Best Answer (HR Friendly)

Overloading means having several methods with the same name but different inputs in one class, and the compiler figures out which one to use. Overriding means a subclass replaces a method it inherited with its own version, and the correct version is chosen automatically at runtime based on the actual object. One is decided ahead of time, the other while the program is running.

Code Example

Overloading vs overriding side by side
class Calculator {
    // Overloading: same name, different parameter lists
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
}

class Shape {
    double area() { return 0; }
}

class Circle extends Shape {
    double r;
    Circle(double r) { this.r = r; }
    // Overriding: same signature, subclass redefines behavior
    @Override
    double area() { return Math.PI * r * r; }
}

Follow-up Questions

  • Can you overload a method by changing only its return type?
  • Can static methods be overridden?
  • What is covariant return type in overriding?
  • What access-modifier rule applies when overriding a method?

MCQ Practice

1. Method overloading is resolved at?

Overloading is resolved by the compiler based on the method signature at the call site.

2. Which is a requirement for valid method overriding?

Overriding requires the same signature (and compatible return type) as the parent method.

3. Static methods in Java support?

Static methods are resolved at compile time by reference type — this is method hiding, not true overriding.

Flash Cards

Overloading in one line?Same method name, different parameter list, resolved at compile time.

Overriding in one line?Subclass redefines a parent method with the same signature, resolved at runtime.

Which is compile-time polymorphism?Overloading.

Which is runtime polymorphism?Overriding, via dynamic dispatch.

1 / 4

Continue Learning