-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.py
More file actions
37 lines (28 loc) · 855 Bytes
/
Inheritance.py
File metadata and controls
37 lines (28 loc) · 855 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
37
class Bird:
def __init__(self, name, voice, color):
self.name = name
self.voice = voice
self.color = color
def fly(self):
print(f"{self.name} is flying")
def eat(self):
print(f"{self.name} is eating")
def sing(self):
print(f"{self.name} is singing - {self.voice}")
def info(self):
print(f"{self.name} - name")
print(f"{self.name} - color")
print(f"{self.name} - voice")
class Pigeon(Bird):
def __init__(self, name, voice, color, favorite_food):
super().__init__(name, voice, color)
self.favorite_food = favorite_food
def walk(self):
print(f"{self.name} is walking")
bird1 = Pigeon("Mark", "LaLaLa", "blue", "breadcrumbs")
bird1.fly()
bird1.sing()
bird1.walk()
bird2= Bird("Bob", "chirp", "green")
bird2.eat()
bird2.sing()