-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance2.py
More file actions
35 lines (27 loc) · 846 Bytes
/
Inheritance2.py
File metadata and controls
35 lines (27 loc) · 846 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
class Person:
def __init__(self, name):
self.name = name
def get_details(self):
return self.name
class Teacher(Person):
def __init__(self, name, subjects):
super().__init__(name)
self.subjects = subjects
def get_details(self):
return "{} teaches {}".format(self.name, ','.join(self.subjects))
class Student(Person):
def __init__(self, name, year):
super().__init__(name)
self.year = year
def get_details(self):
return "{} is studying in {} year".format(self.name, self.year)
person1 = Person('Harry')
print(person1.get_details())
teacher1 = Teacher("Sam", ["C", "Python"])
print(teacher1.get_details())
student1 = Student("Gary", "Second")
print(student1.get_details())
#Output:
Harry
Sam teaches C,Python
Gary is studying in Second year