forked from chavarera/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.Multipleinheritance.py
More file actions
46 lines (32 loc) · 1017 Bytes
/
7.Multipleinheritance.py
File metadata and controls
46 lines (32 loc) · 1017 Bytes
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
# One class extending more than one class is called multiple inheritance.
#parent class 1
class A:
def __init__(self):
print('i am from Class A')
self.name = 'John'
self.age = 23
def getName(self):
return self.name
#parent class 2
class B:
def __init__(self):
print('i am from Class B')
self.name = 'Richard'
self.id = '32'
def getName(self):
return self.name
class C(B,A): #extend two base class
print('i am from Class c')
def __init__(self):
A.__init__(self)
B.__init__(self)
def getName(self):
return self.name
C1 = C()
print(C1.getName())
#When You called c Class then __init__method of c is fist called after calling c class inside init() method
#then class A is called because in C class Initilization we called A class initilization first
#then Class B is called
#firstly name value=jhon
#After calling to B class name value is override with jhon
#So the Final Output is Richard