Polymorphism ka matlab hota hai — "many forms"
Ek hi function ya operator different kaam karein different context mein.
🗣️ “Ek naam, multiple kaam”
| Real World | Polymorphism Concept |
|---|---|
| Tumhara mobile ka volume button: |
Call mein: call volume
Music mein: music volume
| Same button (same name), different kaam |
| Type | Also Called As | When It Happens |
|---|---|---|
| ✅ Compile-time Polymorphism | Static Binding | During compilation |
| ✅ Run-time Polymorphism | Dynamic Binding | During execution |
➡️ Achieved by:
Same function name, different parameters
cpp
CopyEdit
#include<iostream>
using namespace std;
class Print {
public:
void show(int a) {
cout << "Int: " << a << endl;
}
void show(string s) {
cout << "String: " << s << endl;
}
};
int main() {
Print p;
p.show(5); // Int: 5
p.show("Nikhil"); // String: Nikhil
}