-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtutorial21-python-inheritance.py
More file actions
110 lines (84 loc) · 1.27 KB
/
tutorial21-python-inheritance.py
File metadata and controls
110 lines (84 loc) · 1.27 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""class A():
def __init__(self, a):
self.a = a
def display(self):
print("in A class a =", self.a)
class B(A):
def __init__(self, a ,b ):
self.b = b
A.__init__(self, a)
def display_b(self):
print(" in class B a =", self.a)
print(" in class B b =", self.b)
def display(self):
print("in B class a =", self.a)
b1 = B(10, 20)
b1.display_b()
b1.display()
print(b1.a)
"""
"""
Types of Inheritecne
"""
"""
Single inheritance
A
|
B
"""
"""
Multilevel inheritance
A
|
B
|
C
"""
"""class A():
pass
class B( A ):
pass
class C(B):
pass
"""
"""
Multiple inheritance
A B
|_______|
|
C
"""
class A():
def __init__(self, a):
self.a = a
class B():
def __init__(self, b):
self.b = b
class C(A, B):
def __init__(self, a, b, c):
A.__init__(self, a)
B.__init__(self, a)
self.c = c
def display(self):
print(" a =", self.a)
print(" b =", self.b)
print(" c =", self.c)
c1 = C(10, 20, 30)
c1.display()
"""
Hierarchical inheritance
A
___|___
| |
B C
"""
"""
Hybrid inheritance
A
___|___
| |
B C
|_______|
|
D
"""