-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinheritance.py
54 lines (40 loc) · 1.21 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
# Inheritance (Kalıtım): Miras alma
# Person => name, lastname , age, eat(), run(), drink()
# Student(Person), Teacher(Person)
# Animal => Dog(Animal), Cat(Animal)
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.studentNumber = number
print('Student Created')
# override
def who_am_i(self):
print('I am a student')
def sayHello(self):
print('Hello I am a student')
class Teacher(Person):
def __init__(self,fname, lname,branch):
super().__init__(fname, lname)
self.branch = branch
def who_am_i(self):
print(f'I am a {self.branch} teacher')
p1 = Person('Ebubekir','Dogan')
s1 = Student('Selim','Sarac', 1256)
t1 = Teacher('Funda','Yasar','Math')
t1.who_am_i()
print(p1.firstName + ' ' + p1.lastName)
print(s1.firstName + ' ' + s1.lastName+ ' '+ str(s1.studentNumber))
p1.who_am_i()
s1.who_am_i()
p1.eat()
s1.eat()
s1.sayHello()