forked from abhaysamantni/Python_OOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimals.py
More file actions
53 lines (34 loc) · 1.23 KB
/
animals.py
File metadata and controls
53 lines (34 loc) · 1.23 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
# The Mammal class represents a generic mammal.
class Mammal:
# The __init__ method accepts an argument for
# the mammal's species.
def __init__(self, species):
self.__species = species
# The show_species method displays a message
# indicating the mammal's species.
def show_species(self):
print('I am a', self.__species)
# The make_sound method is the mammal's
# way of making a generic sound.
def make_sound(self):
print('Grrrrr')
# The Dog class is a subclass of the Mammal class.
class Dog(Mammal):
# The __init__ method calls the superclass's
# __init__ method passing 'Dog' as the species.
def __init__(self):
Mammal.__init__(self, 'Dog')
# The make_sound method overrides the superclass's
# make_sound method.
def make_sound(self):
print('Woof! Woof!')
# The Cat class is a subclass of the Mammal class.
class Cat(Mammal):
# The __init__ method calls the superclass's
# __init__ method passing 'Cat' as the species.
def __init__(self):
Mammal.__init__(self, 'Cat')
# The make_sound method overrides the superclass's
# make_sound method.
def make_sound(self):
print('Meow')