-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_4_1.py
30 lines (25 loc) · 920 Bytes
/
6_4_1.py
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
#Different classes can have methods with
# the same name but different implementations
# Base class: Hrithik Roshan
class HrithikRoshan:
def role(self):
print("I am Hrithik Roshan, the actor!")
# Subclass 1: Hrithik as a superhero
class lady:
def role(self):
print("I am Hrithik as a lady!")
# Subclass 2: Hrithik as a king
class security_guard:
def role(self):
print("I am Hrithik as a security guard!")
# Function to show polymorphism in action
def show_role(hritik):
hritik.role()
# Creating objects for different forms
hrithik = HrithikRoshan()
second_role = lady()
third_role = security_guard()
# Calling the same method but getting different outputs
show_role(hrithik) # Output: I am Hrithik Roshan, the actor!
show_role(second_role) # Output: I am Hrithik as a superhero!
show_role(third_role) #output : I am Hritik as a security guard!