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 दो प्रकार के होते हैं:
  1. Static Variables: Class-Level Variables जो सभी Objects में समान रहती हैं।
  2. 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 को @staticmethod Decorator का उपयोग करके Define किया जाता है।

Applications of Static Members

Static Members का उपयोग विभिन्न क्षेत्रों में किया जाता है:
  1. Shared Resources: Static Variables का उपयोग Shared Resources को Track करने के लिए किया जाता है।
  2. Utility Functions: Static Methods को Helper या Utility Functions के रूप में उपयोग किया जा सकता है।
  3. 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 Post