forked from imtiazahmad007/PythonCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment_01.py
More file actions
71 lines (48 loc) · 1.51 KB
/
assignment_01.py
File metadata and controls
71 lines (48 loc) · 1.51 KB
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
# Assignment 1:
"""
Define a class hierarchy representing animals with a parent class Animal
and child classes such as dog, fish and bird. Each subclass animal should have
a name and an age and should have 2 methods defined in it: move(), eat().
The move method needs to be specific for a given animal where as the
eat() method should be generic for all animals. The methods don't need to
do anything except print information about who is doing what.
After creating the class hierarchy, create instances of each of the 3 animals
dog, fish and bird and make them eat and move.
"""
class Animal:
def __init__(self):
print("Animal Constructed")
def move(self):
print("Animal Moving...")
def eat(self):
print("Animal Eating...")
class Bird(Animal):
def __init__(self, bird_age, bird_name):
Animal.__init__(self)
self.age = bird_age
self.name = bird_name
def move(self):
print("Bird flying...")
class Fish(Animal):
def __init__(self, bird_age, bird_name):
Animal.__init__(self)
self.age = bird_age
self.name = bird_name
def move(self):
print("Fish Swimming...")
class Dog(Animal):
def __init__(self, bird_age, bird_name):
Animal.__init__(self)
self.age = bird_age
self.name = bird_name
def move(self):
print("Dog Running ...")
mydog = Dog(3, "wolfy")
mydog.move()
mydog.eat()
mydog = Fish(1, "nemo")
mydog.move()
mydog.eat()
mydog = Bird(3, "jojo")
mydog.move()
mydog.eat()