-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_inheritance.py
More file actions
36 lines (26 loc) · 851 Bytes
/
multiple_inheritance.py
File metadata and controls
36 lines (26 loc) · 851 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
# definition of the class starts here
class Person:
# defining constructor
def __init__(self, personName, personAge):
self.name = personName
self.age = personAge
# defining class methods
def showName(self):
print(self.name)
def showAge(self):
print(self.age)
# end of class definition
# defining another class
class Student: # Person is the
def __init__(self, studentId):
self.studentId = studentId
def getId(self):
return self.studentId
class Resident(Person, Student): # extends both Person and Student class
def __init__(self, name, age, id):
Person.__init__(self, name, age)
Student.__init__(self, id)
# Create an object of the subclass
resident1 = Resident('John', 30, '102')
resident1.showName()
print(resident1.getId())