Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class First:
- def __init__(self, a: int, b: int):
- self.a = a
- self.b = b
- self.results = []
- def sum_numbers(self):
- result = self.a + self.b
- self.results.append(result)
- return result
- def subtract_numbers(self):
- result = self.a - self.b
- self.results.append(result)
- return result
- # Inheritance
- class Second(First):
- pass
- class Third(Second):
- pass
- class Fourth(Third):
- pass
- print("----------First class----------")
- obj = First(5, 4)
- print(obj.sum_numbers())
- print(obj.subtract_numbers())
- print(obj.results)
- print("----------Second class----------")
- obj2 = Second(3, 2)
- print(obj2.sum_numbers())
- print(obj2.subtract_numbers())
- print(obj2.results)
- print("----------Third class----------")
- obj3 = Third(20, 10)
- print(obj3.sum_numbers())
- print(obj3.subtract_numbers())
- print(obj3.results)
- print("----------Fourth class----------")
- obj4 = Fourth(10, 5)
- print(obj4.subtract_numbers())
- print(obj4.sum_numbers())
- print(obj4.results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement