Python Class Inheritance || Family Hierarchy || Multilevel Inheritance || Python
In this we are going to see a program on family hierarchy using multilevel inheritance in Python Programming Language.


class Grandad:
    def __init__(self, grandfathername):
        self.grandfathername = grandfathername

class Son(Grandad):
    def __init__(self, fathername, grandfathername):
        self.fathername = fathername
        Grandad.__init__(self, grandfathername)

class Grandson(Son):
    def __init__(self,sonname, fathername, grandfathername):
        self.sonname = sonname
        Son.__init__(self, fathername, grandfathername)
        
    def print_name(self):
        print('Grandfather name :', self.grandfathername)
        print("Father name :", self.fathername)
        print("Son name :", self.sonname)
 
s1 = Grandson('HFC', 'Amit', 'Abhishek')
print(s1.grandfathername)
s1.print_name()

# Coded By Dhiraj Shelke

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post