Python Program using hierarchical inheritance

In this program, you will learn how to implement hierarchical inheritance in Python.

20 = 10 + 10

10 = 20 - 10

Example: How to implement hierarchical inheritance in Python

class First:
    def __init__(self):
        self.x = 20
        self.y = 10

class Second(First):
    def findsum(self):
        self.z = self.x + self.y
        print("Sum is:", self.z)

class Third(First):
    def findsub(self):
        self.z = self.x - self.y
        print("Subtraction is:", self.z)

obj1 = Second()

obj2 = Third()


Sum is: 30
Subtraction is: 10

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.