Skip to main content

Multilevel Inheritance in Python

 





class Dad:
    basketball = 1

class Son(Dad):
    dance = 2
    def idance(self):
        return f"I can Dance {self.dance} no of times"

class Grandson(Son):
    dance= 4
   

a = Dad()
b = Son()
c = Grandson()
print(c.basketball)











                # Exercise

class electronic_device:
    monitor = 2
    keyboard = 3
    circit = 1

    # private or protected
    _prot = 9
    __private = 5
class pocket_device(electronic_device):
    watch = 1
    pendrive = 3
    def  printdet(self):
        return f"I have {self.watch} Watch\nand{self.pendrive} Pendrive"

class phone(pocket_device):
    touchscreen = 1
    cpu = 1
    def printdet(self):
        return f"I have {self.touchscreen} touchscreen\nand {self.cpu} CPU"


a = electronic_device()
b = pocket_device()
c = phone()


                # private or protected member
# print(a._electronic_device__private)
# print(a._prot)




Comments