public just write name
Protected use _name(singel underscore)
Private Use __name
In [19]:
#Public
class car:
wheels=4
a=car()
print(a.wheels)
In [20]:
#Protectd for single calss
class car:
wheels=4
_color="red"
a=car()
print(a.wheels)
print(a._color)
In [23]:
#private for single calss
class car:
wheels=4
_color="red"
class car1(car):
def __init__(self):
print(self._color)
a=car()
print(a.wheels)
#print(a._color)
c=car1()
In [25]:
class car:
wheels=4
_color="red"
__year=2000
a=car()
print(a.wheels)
print(a._color)
print(a.__year)
In [26]:
#private
#private for single calss
class car:
wheels=4
_color="red"
__year=2000
class car1(car):
def __init__(self):
print(self._color)
a=car()
print(a.wheels)
print(a._color)
print(a._car__year)
c=car1()
No comments:
Post a Comment