-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday04_polymorphism.py
More file actions
86 lines (58 loc) · 1.92 KB
/
Copy pathday04_polymorphism.py
File metadata and controls
86 lines (58 loc) · 1.92 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#------------------------------------------------------------------------------------------------------------------
#Polymorphism
#------------------------------------------------------------------------------------------------------------------
#1.Method Overriding with a single child class
class Animal:
def sound(self):
print("Sound of an animal")
class Dog(Animal):
def sound(self):
print("Dog Barks")
d = Dog()
d.sound()
#--------------------------------------------------------------------------------------------------------------------
#2.Method Overriding with multiple child class
class Employee:
def work(self):
print("Works good")
class Manager(Employee):
def work(self):
print("Manages all the activities.")
class Tester(Employee):
def work(self):
print("Tests the products before manufacturing.")
m = Manager()
t = Tester()
m.work()
t.work()
#--------------------------------------------------------------------------------------------------------------------
#3.Payment System
class Payment:
def pay(self):
print("Payment in process")
class creditcard(Payment):
def pay(self):
print("Payment done by using Creditcard.")
class UPI(Payment):
def pay(self):
print("Payment done by using UPI.")
c = creditcard()
a = UPI()
c.pay()
a.pay()
#---------------------------------------------------------------------------------------------------------------------
#4.Onile shopping
class shopping_onile:
def usage(self):
print("The rate of Online shopping increased gardually.")
class male_users(shopping_online):
def usage(self):
print("70% of men prefers Online shopping.")
class female_users(shopping_online):
def usage(self):
print("90% of women prefers to shop online.")
ob1 = male_users()
ob2 = female_users()
ob1.usage()
ob2.usage()
#-----------------------------------------------------------------------------------------------------------------------