Hierarchical Inheritance in Python || Operations || Hierarchical Inheritance || Python
In this we are going to see a program of operations using hierarchical inheritance in Python Programming Language.



class Upper_parent:
    def subraction(self):
        print("Subraction value1 : ", self.value1)
        print("Subraction value2 : ", self.value2)
        return self.value1 - self.value2

    def mod(self):
        print("Modulus value1 : ", self.value1)
        print("Modulus value2 : ", self.value2)
        return self.value1 % self.value2


class Parent_class1(Upper_parent):
    def __init__(self, value1, value2):
        self.value1 = value1
        self.value2 = value2

    def Addition(self):
        print("Addition value1 : ", self.value1)
        print("Addition value2 : ", self.value2)
        return self.value1 + self.value2

    def multiplication(self):
        print("Multiplication value1 : ", self.value1)
        print("Multiplication value2 : ", self.value2)
        return self.value1 * self.value2


class Parent_class2(Upper_parent):
    def __init__(self, value1, value2):
        self.value1 = value1
        self.value2 = value2

    def divison(self):
        print("Division value1 : ", self.value1)
        print("Division value2 : ", self.value2)
        return self.value1 / self.value2

    def power(self):
        print("Power value1 : ", self.value1)
        print("Power value2 : ", self.value2)
        return self.value1 ** self.value2


Object1 = Parent_class1(10, 15)
print("Added value :", Object1.Addition())
print(" ")
Object2 = Parent_class1(20, 30)
print("Multiplied value :", Object2.multiplication())
print(" ")
Object3 = Parent_class2(50, 30)
print("Subracted value :", Object3.subraction())
print(" ")
Object4 = Parent_class2(70, 20)
print("Division value :", Object4.divison())
print(" ")
Object5 = Parent_class2(6, 2)
print("Power value :", Object5.power())
print(" ")
Object6 = Parent_class2(16, 7)
print("Modulus value :", Object6.mod())

# Coded by Saahil


#ENJOY CODING


Post a Comment

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

Previous Post Next Post