-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.7inheritance.py
More file actions
34 lines (28 loc) · 1.16 KB
/
4.7inheritance.py
File metadata and controls
34 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Write a program to implement Multilevel inheritance, Grandfather→Father-→Child to show property inheritance from grandfather to child.
class Grandfather:
def __init__(self, assets):
self.assets = assets
class Father(Grandfather):
def __init__(self, assets, business):
super().__init__(assets)
self.business = business
class Child(Father):
def __init__(self, assets, business, education):
super().__init__(assets, business)
self.education = education
grandfather_assets = 1000
father_assets = 5000
business_info = "Family Business"
child_education = "Computer Science Engineer"
#instance
grandfather = Grandfather(assets=grandfather_assets)
father = Father(assets=father_assets, business=business_info)
child = Child(assets=None, business=None, education=None)
child.assets = grandfather.assets + father.assets
child.business = father.business
child.education = child_education
print(f"\nGrandfather's assets: ₹{grandfather.assets}")
print(f"Father's assets: ₹{father.assets}")
print(f"Child's assets: ₹{child.assets}")
print(f"\nChild's business: {child.business}")
print(f"\nChild's education: {child.education}\n")