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 Post
- Introduction to Object-Oriented Thinking in Hindi – Definition, Concepts, and Examples
- Difference between OOP and POP in Hindi – Object-Oriented Programming vs Procedural Programming
- Features of Object-Oriented Paradigm – Merits and Demerits of OO Methodology in Hindi
- Object Model and Elements of OOPS in Hindi – Definition, Components, and Examples
- I/O Processing in Object-Oriented Programming in Hindi – Definition, Types, and Examples
- Encapsulation and Data Abstraction in Object-Oriented Programming in Hindi – Definition, Difference, and Examples
- Concept of Objects in OOP – State, Behavior, and Identity in Hindi
- Message Passing in Object-Oriented Programming in Hindi – Definition, Process, and Examples
- Construction and Destruction of Objects in Object-Oriented Programming in Hindi – Definition, Process, and Examples
- Classes in Object-Oriented Programming in Hindi – Identifying Classes, Attributes, and Services
- Access Modifiers in Object-Oriented Programming in Hindi – Definition, Types, and Examples
- Static Members of a Class in Object-Oriented Programming in Hindi – Definition, Uses, and Examples
- Instances in Object-Oriented Programming in Hindi – Definition, Creation, and Examples
- Inheritance and Its Types in Object-Oriented Programming in Hindi – Definition, Types, and Examples
- 'is a' Relationship, Association, and Aggregation in Object-Oriented Programming in Hindi – Definition, Examples, and Uses
- Concept of Interface and Abstract Classes in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
- Polymorphism in Object-Oriented Programming in Hindi – Introduction, Types, and Examples
- Method Overriding and Overloading in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
- Static and Run-Time Polymorphism in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
- Exception Handling in Object-Oriented Programming in Hindi – Definition, Types, and Examples
- Multithreading and Data Collection in Hindi – Definition, Uses, and Examples