-
Notifications
You must be signed in to change notification settings - Fork 1
/
inheritance.py
60 lines (39 loc) · 936 Bytes
/
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
class Animal():
def __init__(self):
print("Animal Created")
def who_am_i(self):
print("I am an animal")
def eat(self):
print("I am eating")
class Dog(Animal):
def __init__(self):
Animal.__init__(self)
print("Dog created")
def eat(self):
print("I am eating meat")
def bark(self):
print("Woof!")
"""my_animal = Dog()
print(my_animal.who_am_i())"""
# parent class
class Bird:
def __init__(self):
print("Bird is ready")
def whoisThis(self):
print("Bird")
def swim(self):
print("Swim faster")
# child class
class Penguin(Bird):
def __init__(self):
# call super() function
super().__init__()
print("Penguin is ready")
def whoisThis(self):
print("Penguin")
def run(self):
print("Run faster")
peggy = Penguin()
peggy.whoisThis()
peggy.swim()
peggy.run()