-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.py
More file actions
34 lines (28 loc) · 976 Bytes
/
polymorphism.py
File metadata and controls
34 lines (28 loc) · 976 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
# # Polymorphism
'''--> Polymorphism allows objects of different classes to be treated as object of a common superclass,
but they can behave differently depending on the object type.
--> Real-worldExample: Think of animals making sounds-both dogs and cats make sounds,
but each produces a distinct sound.
They share a common method make_sound(), but the output varies.
'''
# class Animal:
# def make_sound(self):
# print("Animal make sound")
# class Dog(Animal):
# def make_sound(self):
# print("Bark")
# class cat(Animal):
# def make_sound(self):
# print("meow")
# animals = [Dog(),cat()]
# for animal in animals:
# animal.make_sound()
class notification:
def send(self):
print("notification sent")
class EmailNotification(notification):
def send(self):
print("email sent")
class smsnotification(notification):
def send(self):
print("sms sent")