Static and Run-Time Polymorphism 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
Static और Run-Time Polymorphism क्या हैं?
Object-Oriented Programming (OOP) में Polymorphism दो प्रकार का होता है: Static Polymorphism और Run-Time Polymorphism। दोनों का उपयोग Code को अधिक Dynamic और Reusable बनाने के लिए किया जाता है।
Static Polymorphism की परिभाषा (Definition of Static Polymorphism)
Static Polymorphism को Compile-Time Polymorphism भी कहा जाता है। यह Method Overloading और Operator Overloading के माध्यम से प्राप्त होता है। Static Polymorphism में Method का निर्णय Compile-Time पर होता है।
Example of Static Polymorphism (Method Overloading):
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
Run-Time Polymorphism की परिभाषा (Definition of Run-Time Polymorphism)
Run-Time Polymorphism को Dynamic Polymorphism भी कहा जाता है। यह Method Overriding के माध्यम से प्राप्त होता है। Method का निर्णय Run-Time पर किया जाता है।
Example of Run-Time Polymorphism (Method Overriding):
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
Difference between Static and Run-Time Polymorphism
| Feature | Static Polymorphism | Run-Time Polymorphism |
|---|---|---|
| Definition | Method का निर्णय Compile-Time पर होता है। | Method का निर्णय Run-Time पर होता है। |
| Implementation | Method Overloading और Operator Overloading के माध्यम से। | Method Overriding के माध्यम से। |
| Polymorphism Type | Compile-Time Polymorphism | Dynamic Polymorphism |
| Performance | Performance बेहतर होती है क्योंकि निर्णय Compile-Time पर होता है। | Run-Time पर Method चुनने के कारण Performance थोड़ा कम होती है। |
Advantages of Static and Run-Time Polymorphism
Static Polymorphism:
- Code को अधिक Readable और Maintainable बनाता है।
- Compile-Time Errors को कम करता है।
- Performance बेहतर होती है।
Run-Time Polymorphism:
- Code को अधिक Dynamic और Flexible बनाता है।
- Parent Class के Methods को Customize करने की सुविधा।
- Extensibility को बढ़ाता है।
Applications of Static and Run-Time Polymorphism
इनका उपयोग विभिन्न क्षेत्रों में किया जाता है:
- Game Development
- Database Management Systems
- User Interface Design
- Real-Time Systems
- Simulation Systems
Conclusion
Static और Run-Time Polymorphism Object-Oriented Programming के महत्वपूर्ण हिस्से हैं। Static Polymorphism Compile-Time पर Method का निर्णय करता है, जबकि Run-Time Polymorphism Method का निर्णय Run-Time पर करता है। दोनों की समझ Software Design को अधिक Dynamic और Reusable बनाती है।
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 →Method Overriding and Overloading in Object-Oriented Programming in Hindi – Definition, Differences, and Examples
Method Overriding और Method Overloading क्या हैं? Object-Oriented Programming (OOP) म...
Read More →Polymorphism in Object-Oriented Programming in Hindi – Introduction, Types, and Examples
Polymorphism क्या है? Object-Oriented Programming (OOP) में Polymorphism...
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 →