Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · Java · 04 Jul 2026 · Hindi + English

Method Overloading vs Overriding in Java (Table + Rules)

Overloading = same name, different parameters, same class, compile-time. Overriding = same signature, child class, runtime. Full rules and code proof.

The one-line answer

Overloading = same method name, DIFFERENT parameters, SAME class, resolved at compile time. Overriding = SAME signature, CHILD class redefines parent's method, resolved at runtime.

Overloading example (compile-time polymorphism)

class Calculator {
    int add(int a, int b)          { return a + b; }
    int add(int a, int b, int c)   { return a + b + c; }   // more params
    double add(double a, double b) { return a + b; }        // diff types
}

Calculator c = new Calculator();
System.out.println(c.add(2, 3));
System.out.println(c.add(2, 3, 4));
System.out.println(c.add(2.5, 3.5));
5 9 6.0

The compiler picks the right version by looking at the arguments — decided before the program even runs.

Trap: changing only the return type is NOT overloading — int add(int,int) and double add(int,int) together is a compile error. Parameters must differ in number, type, or order.

Overriding example (runtime polymorphism)

class Animal {
    void sound() { System.out.println("Some generic sound"); }
}

class Dog extends Animal {
    @Override
    void sound() { System.out.println("Bark!"); }    // same signature
}

Animal a = new Dog();     // parent reference, child object
a.sound();                // which version runs?
Bark!

Even though the reference type is Animal, the object's version runs — the JVM decides at runtime by looking at the actual object. This is runtime (dynamic) polymorphism, the backbone of frameworks like Spring.

Comparison table

PointOverloadingOverriding
ParametersMust be differentMust be identical
Classes involvedSame class (or child adding)Parent + child required
ResolvedCompile time (static)Runtime (dynamic)
Return typeCan differ freelySame or covariant
Access modifierAnyCannot be more restrictive
static/final/privateCan be overloadedCannot be overridden
Annotation@Override (recommended)

Overriding rules interviewers test

  • Same signature: name + parameters must match exactly.
  • Access cannot shrink: a public parent method cannot become protected in the child.
  • static methods: cannot be overridden — a same-signature static in the child is method hiding, resolved by reference type, not object.
  • final and private methods: cannot be overridden at all.
  • @Override annotation: optional but always use it — the compiler then catches signature typos that would silently create an overload instead.

One-line answer

Overloading = same method name, ALAG parameters, SAME class, compile time पर resolve. Overriding = SAME signature, CHILD class parent का method redefine करती है, runtime पर resolve.

Overloading example (compile-time polymorphism)

class Calculator {
    int add(int a, int b)          { return a + b; }
    int add(int a, int b, int c)   { return a + b + c; }   // ज़्यादा params
    double add(double a, double b) { return a + b; }        // अलग types
}

Calculator c = new Calculator();
System.out.println(c.add(2, 3));
System.out.println(c.add(2, 3, 4));
System.out.println(c.add(2.5, 3.5));
5 9 6.0

Compiler arguments देखकर सही version चुनता है — program चलने से पहले ही decide.

Trap: सिर्फ return type बदलना overloading NAHI है — int add(int,int) और double add(int,int) साथ में compile error है. Parameters number, type, या order में अलग होने चाहिए.

Overriding example (runtime polymorphism)

class Animal {
    void sound() { System.out.println("Some generic sound"); }
}

class Dog extends Animal {
    @Override
    void sound() { System.out.println("Bark!"); }    // same signature
}

Animal a = new Dog();     // parent reference, child object
a.sound();                // कौन-सा version चलेगा?
Bark!

Reference type Animal होने के बावजूद object का version चला — JVM runtime पर actual object देखकर decide करता है. यही runtime (dynamic) polymorphism है, Spring जैसे frameworks की रीढ़.

Comparison table

PointOverloadingOverriding
Parametersअलग होने ज़रूरीIdentical होने ज़रूरी
ClassesSame classParent + child ज़रूरी
ResolveCompile time (static)Runtime (dynamic)
Return typeआज़ादी से अलगSame या covariant
Access modifierकोई भीज़्यादा restrictive नहीं हो सकता
static/final/privateOverload हो सकते हैंOverride नहीं हो सकते
Annotation@Override (recommended)

Overriding rules जो interviewers test करते हैं

  • Same signature: name + parameters exactly match होने चाहिए.
  • Access घट नहीं सकता: public parent method child में protected नहीं बन सकता.
  • static methods: override नहीं होते — child में same-signature static method hiding है, जो object से नहीं, reference type से resolve होती है.
  • final और private methods: override हो ही नहीं सकते.
  • @Override annotation: optional है पर हमेशा लगाएं — compiler फिर signature typos पकड़ लेता है जो चुपचाप overload बना देते.

Frequently Asked Questions

What is the difference between overloading and overriding?

Overloading is same method name with different parameters in the same class, resolved at compile time; overriding is a child class redefining a parent method with the identical signature, resolved at runtime.

Can we override a static method in Java?

No. A same-signature static method in the child is method hiding, not overriding — it is resolved by reference type, not by the actual object.

Is changing only the return type overloading?

No, it is a compile error. Overloaded methods must differ in the number, type, or order of parameters.