-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.py
78 lines (53 loc) · 1.58 KB
/
Inheritance.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class Person():
def __init__(self):
print("person created")
class Student(Person):
pass
p1 = Person()
s1 = Student()
#####
class Person():
def __init__(self):
print("person created")
class Student(Person):
def __init__(self):
Person.__init__(self)
print("Student created")
s2 = Student()
#####
class Person():
def __init__(self , fname , lname):
self.firstname = fname
self.lastname = lname
print("person created")
def who_am_i(self):
print("I am a person")
def eat(self):
print("I am eating")
class Student(Person):
def __init__(self, fname , lname, number):
Person.__init__(self, fname , lname)
self.student_number = number
print("Student created")
# override
def who_am_i(self):
print("I am a student")
def sayHello(self):
print("Hello there I am a student")
class Teacher(Person):
def __init__(self , fname , lname , branch):
Person.__init__(self, fname, lname)
self.brn = branch
def who_am_i(self):
print("I am a teacher")
t1 =Teacher('Ahmet', 'yılmaz', 'math')
print(t1.firstname + ' ' + t1.lastname + ' ' + t1.brn)
p2 = Person('Batu', 'yılmaz')
s3 = Student('Çınar', 'turan',1256)
print(p2.firstname + " " + p2.lastname)
print(s3.firstname + " " + s3.lastname + " " + str(s3.student_number) )
p2.who_am_i()
s3.who_am_i()
p2.eat()
s3.eat()
s3.sayHello()