Constructor Single Inheritance in Python || init || Python
In this we are going to see a program on single inheritance of constructor in Python Programming Language.


class Animals:
    def __init__(self):
        self.hasLegs = 4
        self.domestic = True
        self.hasTail = True
        self.mammals = True
     
    def checkIfMammal(self):
        if self.mammals:
            print("This animal is a Mammal.")
     
    def checkIfDomestic(self):
        if self.domestic:
            print("This animal is a domestic animal.")
     
class Dogs(Animals):
    def __init__(self):
        super().__init__()
 
    def checkIfMammal(self):
        super().checkIfMammal()
 
class Horses(Animals):
    def __init__(self):
        super().__init__()
 
    def hasTailandLegs(self):
        if self.hasTail and self.hasLegs == 4:
            print("This animal has 4 legs and a tail")

Charlie = Dogs()
print("Charlie is a Dog.", end=" ")
Charlie.checkIfMammal()
Chip = Horses()
print("Chip is a Horse.", end=" ")
Chip.hasTailandLegs()

# 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