Polymorphism in Object-Oriented Programming in Hindi – Introduction, Types, and Examples
Polymorphism in Object-Oriented Programming in Hindi – Introduction, Types, and Examples
Polymorphism क्या है?
Object-Oriented Programming (OOP) में Polymorphism एक महत्वपूर्ण अवधारणा है, जिसका शाब्दिक अर्थ है “Many Forms” यानी एक ही चीज़ के कई रूप। Polymorphism का उपयोग एक ही Method को विभिन्न Context में अलग-अलग तरह से उपयोग करने के लिए किया जाता है।
Polymorphism की परिभाषा (Definition of Polymorphism)
Polymorphism एक ऐसी प्रक्रिया है, जिसमें एक Function, Method या Operator को विभिन्न Objects के लिए अलग-अलग तरीकों से उपयोग किया जा सकता है। यह Code को अधिक Dynamic और Reusable बनाता है।
Types of Polymorphism (Polymorphism के प्रकार)
Polymorphism मुख्य रूप से दो प्रकार का होता है:- Compile-Time Polymorphism (Static Polymorphism): इसे Method Overloading और Operator Overloading के रूप में जाना जाता है।
- Run-Time Polymorphism (Dynamic Polymorphism): इसे Method Overriding के रूप में जाना जाता है।
1. Compile-Time Polymorphism (Method Overloading)
Compile-Time Polymorphism में एक ही Method का नाम विभिन्न Parameters के साथ उपयोग किया जाता है।
Python Example:
class MathOperations:
def add(self, a, b, c=0):
return a + b + c
math = MathOperations()
print(math.add(2, 3)) # Output: 5
print(math.add(2, 3, 4)) # Output: 9
2. Run-Time Polymorphism (Method Overriding)
Run-Time Polymorphism में Child Class Parent Class के Method को Override करती है।
Python Example:
class Animal:
def sound(self):
print("Animal makes a sound")
class Dog(Animal):
def sound(self):
print("Dog barks")
animal = Animal()
dog = Dog()
animal.sound() # Output: Animal makes a sound
dog.sound() # Output: Dog barks
Advantages of Polymorphism
- Code Reusability: एक ही Method को कई Objects के लिए उपयोग किया जा सकता है।
- Code Maintainability: Code को Maintain करना आसान बनाता है।
- Extensibility: नए Features को आसानी से जोड़ा जा सकता है।
- Dynamic Behavior: Programs अधिक Dynamic बनते हैं।
Applications of Polymorphism
Polymorphism का उपयोग विभिन्न क्षेत्रों में किया जाता है:
- Software Development
- Game Development
- Real-Time Systems
- Database Systems
- User Interface Design
Conclusion
Polymorphism Object-Oriented Programming का एक शक्तिशाली सिद्धांत है। यह Method Overloading और Method Overriding के माध्यम से Code को अधिक Reusable और Dynamic बनाता है। इसकी समझ Software Design को बेहतर बनाने में सहायक होती है।
Related Articles
Multithreading and Data Collection in Hindi – Definition, Uses, and Examples
Multithreading क्या है? Multithreading एक Programming Technique है, ...
Read More →Exception Handling in Object-Oriented Programming in Hindi – Definition, Types, and Examples
Exception Handling क्या है? Object-Oriented Programming (OOP) में Exception Handl...
Read More →Static and Run-Time Polymorphism in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
Static और Run-Time Polymorphism क्या हैं? Object-Oriented Programming (OOP) में ...
Read More →Method Overriding and Overloading in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
Method Overriding और Method Overloading क्या हैं? Object-Oriented Programming (OOP) म...
Read More →Concept of Interface and Abstract Classes in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
Interface और Abstract Class क्या हैं? Object-Oriented Programming (OOP) में ...
Read More →