🟣 OOP  ·  Lesson 20

Polymorphism

Polymorphism

What is Polymorphism?

Polymorphism means "many forms" — the same method name behaves differently in different situations.

Overloading vs Overriding

TypeMeaning
Overloadingsame name, different parameters (compile-time)
Overridingchild redefines parent method (run-time)

Overriding Example

class Animal { void sound() { System.out.println("some sound"); } }
class Cat extends Animal { void sound() { System.out.println("meow"); } }

Animal a = new Cat();
a.sound();   // meow (child version runs)
meow

Summary

  • Overloading = same name, different parameters (compile-time).
  • Overriding = child redefines parent method (run-time).

Polymorphism क्या है?

Polymorphism का मतलब "कई रूप" — एक ही method नाम अलग situations में अलग व्यवहार करता है।

Overloading बनाम Overriding

Typeमतलब
Overloadingएक नाम, अलग parameters (compile-time)
Overridingchild parent method redefine करे (run-time)

Overriding Example

class Animal { void sound() { System.out.println("some sound"); } }
class Cat extends Animal { void sound() { System.out.println("meow"); } }

Animal a = new Cat();
a.sound();   // meow (child version चलता है)
meow

सारांश

  • Overloading = एक नाम, अलग parameters (compile-time)।
  • Overriding = child parent method redefine करे (run-time)।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n