Multilevel Inheritance And Exercise

Exercise Given In Video, Code of Exercise :

# electronic device
# pocket gadget
# phone


class Electronic_device:
device1 = "camera"
device2 = "Battery"

class Pocket_gadget(Electronic_device):
device1 = "pocket camera"
device2 = "Powerbank"
def cameratype(self):
f"I have a {self.device2} type of battery which can recharge a discharged device (mobile,etc)."

class Phone(Pocket_gadget):
device1 = "Phone Camera"
device2 = "Ion Battery"

def cameratype(self):
return f"I have a {self.device2} type of battery which can keep running a mobile device."


ecd = Electronic_device()
pog = Pocket_gadget()
pho = Phone()

print(pho.device2)

# Output:

# Ion Battery 

Code For Topic  :

class Dad:

    basketball =6


class Son(Dad):

    dance =1

    basketball = 9

    def isdance(self):

        return f"Yes I dance {self.dance} no of times"


class Grandson(Son):

    dance =6

    guitar = 1


    def isdance(self):

        return f"Jackson yeah!" \

            f"Yes I dance very awesomely {self.dance} no of times"


darry = Dad()

larry = Son()

harry = Grandson()


# print(darry.guitar)


# electronic device

# pocket gadget

# phone




Comments

Popular posts from this blog

Pickle Module

Python File IO Basics