Advertisements
Advertisements
प्रश्न
Differentiate between class attributes and instance attributes.
फरक स्पष्ट करा
Advertisements
उत्तर
| Basis of Difference | Class Attributes | Instance Attributes |
|---|---|---|
| Meaning | Attributes that belong to the class. | Attributes that belong to an individual object. |
| Declaration | Defined directly inside the class body. | Usually defined using self inside __init__ or another method. |
| Sharing | Shared by all instances of the class. | Separate copy/value for each instance. |
| Access | Accessed using ClassName.attribute or object.attribute. |
Generally accessed using object.attribute. |
| Example | school = "DPS" |
self.name = name |
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
