Static Members of a Class in Object-Oriented Programming in Hindi – Definition, Uses, and Examples
Static Members of a Class in Object-Oriented Programming in Hindi – Definition, Uses, and Examples
Static Members of a Class क्या हैं?
Object-Oriented Programming (OOP) में Static Members वे Attributes और Methods होते हैं, जो Class Level पर Define किए जाते हैं और Object के बजाय Class के लिए Shared रहते हैं। इन्हें Class Variables और Class Methods भी कहा जाता है। Static Members को Access करने के लिए Class का उपयोग किया जाता है, न कि किसी Specific Object का।
Static Members की परिभाषा (Definition of Static Members)
Static Members Class का हिस्सा होते हैं और वे सभी Objects के बीच Shared होते हैं। इन्हें static Keyword के साथ Declare किया जाता है। Static Members को बिना Object बनाए भी Access किया जा सकता है।
Types of Static Members
Static Members दो प्रकार के होते हैं:- Static Variables: Class-Level Variables जो सभी Objects में समान रहती हैं।
- Static Methods: Methods जो Class-Level पर कार्य करती हैं और केवल Static Variables को Access कर सकती हैं।
Example of Static Members in Python:
class Student:
school_name = "ABC School" # Static Variable
@staticmethod
def get_school_name():
return Student.school_name # Accessing Static Variable inside Static Method
# Access Static Variable and Method without creating an Object
print(Student.school_name) # Output: ABC School
print(Student.get_school_name()) # Output: ABC School
Static Variables (Class Variables)
- Class के सभी Objects में समान रहती हैं।
- Static Variables को Class के नाम से Access किया जा सकता है।
- Memory में केवल एक बार Allocate होती हैं।
Static Methods
- Static Methods को Class Level पर Define किया जाता है।
- यह केवल Static Variables को Access कर सकते हैं।
- Python में Static Methods को
@staticmethodDecorator का उपयोग करके Define किया जाता है।
Applications of Static Members
Static Members का उपयोग विभिन्न क्षेत्रों में किया जाता है:- Shared Resources: Static Variables का उपयोग Shared Resources को Track करने के लिए किया जाता है।
- Utility Functions: Static Methods को Helper या Utility Functions के रूप में उपयोग किया जा सकता है।
- Configuration Settings: Static Variables को Global Configuration Settings के रूप में Define किया जा सकता है।
Advantages of Static Members
Static Members के कई फायदे हैं:
- Memory Utilization में सुधार।
- Global Access की सुविधा।
- Utility Methods को Define करना आसान।
Conclusion
Static Members Object-Oriented Programming का एक महत्वपूर्ण हिस्सा हैं। Static Variables सभी Objects में Shared रहती हैं, जबकि Static Methods को Class Level पर उपयोग किया जाता है। इनकी समझ Software Design में बेहतर Memory Utilization और Efficiency प्रदान करती है।
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 →Polymorphism in Object-Oriented Programming in Hindi – Introduction, Types, and Examples
Polymorphism क्या है? Object-Oriented Programming (OOP) में Polymorphism...
Read More →