-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance_In_Pyhton.py
64 lines (48 loc) · 1.32 KB
/
Inheritance_In_Pyhton.py
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
# Inheritance in pyhton . .
class A:
def feature1(self):
print("feature1 working . . ")
# single level inheritance . .
class B(A):
# inti function . .
def __init__(self):
print("In b init . .")
def feature2(self):
print("feature2 working . . ")
a1 = A()
b1 = B()
a1.feature1()
b1.feature1()
b1.feature2()
# multi-level inheritance . .
class C(B):
def __init__(self):
super().__init__()
print("In c init . .")
# class C is subclass of class B so class c can use class b init function . .
# If you create object of sub class it will first try find init of sub class
# if it is not found then it will call init of super class
def feature3(self):
print("feature3 working . . ")
c1 = C()
c1.feature3()
# multiple inheritance . .
class D(C, B):
def __init__(self):
super().__init__()
print("In d init . .")
# multiple inheritence using comma separated classes in parenthesis
def feature4(self):
return super().feature4()
d1 = D()
# multi-level Inheritance . .
class X:
print("Feature x working . .")
class Y(X):
print("feature y working . .")
class Z(Y):
print("feature z working . .")
# multiple inheritance . .
class W(Z, Y):
pass
z1 = Z()