Interview Q&A / Object-Oriented Programming

BeginnerIn-depth3 min readUpdated 2 Oct 2026

What is the difference between method overloading and method overriding?

SHORT ANSWER

Overloading means several methods in the same class share a name but take different parameters, and the compiler picks one. Overriding means a subclass gives its own version of a method it inherited, with the same signature, and the JVM picks the version at runtime based on the actual object.

Explain it simply

Overloading is like a single "Pay" button in a food delivery app that accepts different inputs. Pay with a UPI ID, pay with a card number and CVV, or pay with wallet balance. Same name, different things you hand over. The app decides which flow to run by looking at what you gave it.

Overriding is like a family recipe for dal that every generation tweaks. The child inherits "make dal" from the parent but cooks it their own way. When someone asks for dal at the child's house, they get the child's version, even though the name of the dish never changed.

Example

java
class Calculator {
    // Overloading: same name, different parameter lists
    int add(int a, int b) { return a + b; }
    int add(int a, int b, int c) { return a + b + c; }
    double add(double a, double b) { return a + b; }
}

class Notification {
    String send() { return "Generic notification"; }
}

class SmsNotification extends Notification {
    @Override
    String send() { return "SMS sent"; }      // Overriding: same signature, new behaviour
}

public class Demo {
    public static void main(String[] args) {
        Calculator c = new Calculator();
        System.out.println(c.add(2, 3));        // prints: 5
        System.out.println(c.add(2, 3, 4));     // prints: 9
        System.out.println(c.add(2.5, 1.5));    // prints: 4.0

        Notification n = new SmsNotification();
        System.out.println(n.send());           // prints: SMS sent
    }
}

How it works

OverloadingOverriding
WhereSame class (or inherited methods plus new ones)Parent and child class
Method nameSameSame
ParametersMust differ in number, type or orderMust be the same
Return typeCan differ, but cannot be the only differenceSame, or a subtype (covariant return)
DecidedAt compile timeAt runtime
Also calledCompile-time (static) polymorphismRuntime (dynamic) polymorphism

Rules for overriding in Java:

  • The access level cannot be more restrictive. A public method cannot become protected in the child.
  • The child cannot declare new or broader checked exceptions.
  • static, private and final methods cannot be overridden.
  • Use @Override so the compiler catches typos and signature mismatches.

Real-world use

  • Overloading: System.out.println has versions for int, String, char[], Object and more. Math.max works for int, long, float and double.
  • Overriding: toString(), equals() and hashCode() from Object; each payment type in a gateway providing its own pay(); each Spring controller overriding behaviour from a base class.

Common mistakes

  • Thinking you can overload by changing only the return type. int total() and double total() will not compile together.
  • Accidentally overloading when you meant to override, for example writing equals(Student other) instead of equals(Object other). @Override would flag it.
  • Saying static methods are overridden. A child static method with the same signature hides the parent's, and the reference type decides which one runs.

What to say in the interview

"Overloading is having several methods with the same name but different parameter lists, usually in the same class, and the compiler chooses which to call based on the arguments, so it's compile-time polymorphism. Overriding is when a subclass provides its own implementation of an inherited method with the same signature, and the JVM picks the method based on the actual object at runtime, so it's runtime polymorphism. For overriding, the return type must be the same or a subtype, access can't be narrowed, and I always add @Override so the compiler checks it."

Follow-up questions

  • Can we overload the main method? Can we override it?
  • Can a constructor be overridden?
  • What is a covariant return type?
  • Can a private method be overridden?

Go deeper

Read these once the basics above feel easy.

When several overloads could match, the compiler chooses the most specific one in phases: first exact matches and widening (an int can become a long), then autoboxing (int to Integer), and only then varargs. So with print(long x) and print(Integer x), calling print(5) picks print(long), because widening is tried before boxing. Overload choice uses the declared type of the argument, not the runtime type, which is why Object o = "hi"; print(o); calls print(Object) even if print(String) exists.

#oop#polymorphism#overloading#overriding#java

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.