0% found this document useful (0 votes)
7 views

6. Inheritance Python

The document presents a Python program demonstrating inheritance through a family hierarchy with classes for Father, Mother, Son, and Grandson. It showcases object creation, method overriding, and attribute setting, highlighting the relationships and properties of each class. The output illustrates the performance of inheritance with details on height, color, and achievements of the objects created.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

6. Inheritance Python

The document presents a Python program demonstrating inheritance through a family hierarchy with classes for Father, Mother, Son, and Grandson. It showcases object creation, method overriding, and attribute setting, highlighting the relationships and properties of each class. The output illustrates the performance of inheritance with details on height, color, and achievements of the objects created.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

6.

Inheritance-Python

#Program using Inheritance

def show_title():

print("!"*30)

print("Performance of Inheritance")

print("!"*30)

class fath:

def __init__(self):

print("Father object is created")

def set_height(self,ht):

self.height=ht

class moth:

def __init__(self):

print("Mother object is created")

self.color="White"

def set_color(self,clr):

self.color=clr

class son(fath,moth):

def __init__(self):

print("Son object is created")

moth.__init__(self)

fath.__init__(self)

def show(self):

print("height :",self.height)

print("color :",self.color)
class grandson(son):

def __init__(self):

print("GrandSon object is created")

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")

print("After 5 yrs back"); s.show()

gs=grandson();gs.set_height(170);gs.set_color("white")

gs.set_achievement("Best example for inherit concept")

gs.show_all()

Output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Performance of Inheritance

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Son object is created

Mother object is created

Father object is created

height : 160
color : White

After 5 yrs back

height : 160

color : pink

GrandSon object is created

height : 170

color : white

Achievement: Best example for inherit concept

You might also like