6. Inheritance Python
6. Inheritance Python
Inheritance-Python
def show_title():
print("!"*30)
print("Performance of Inheritance")
print("!"*30)
class fath:
def __init__(self):
def set_height(self,ht):
self.height=ht
class moth:
def __init__(self):
self.color="White"
def set_color(self,clr):
self.color=clr
class son(fath,moth):
def __init__(self):
moth.__init__(self)
fath.__init__(self)
def show(self):
print("height :",self.height)
print("color :",self.color)
class grandson(son):
def __init__(self):
def set_achievement(self,a):
self.achievement=a
def show_all(self):
son.show(self)
print("Achievement:",self.achievement)
#Again
show_title()
s=son();s.set_height(160);s.show();s.set_color("pink")
gs=grandson();gs.set_height(170);gs.set_color("white")
gs.show_all()
Output:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Performance of Inheritance
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
height : 160
color : White
height : 160
color : pink
height : 170
color : white