-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphism.py
More file actions
37 lines (29 loc) · 888 Bytes
/
Polymorphism.py
File metadata and controls
37 lines (29 loc) · 888 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
35
36
37
class Characters:
def __init__(self, name, character):
self.name = name
self.character = character
def show(self):
print("Base characters show method.")
class JJK(Characters):
def __init__(self, name, character):
super().__init__(name, character)
def show(self):
print(f" Anime: {self.name}, strongest: {self.character}")
class TG(Characters):
def __init__(self, name, character):
super().__init__(name, character)
def show(self):
print(f" Dark anime: {self.name}, main: {self.character}")
# List of different objects (parent type reference)
animes = [JJK("Jujutsu Kaisen", "Gojo"), TG("Tokyo Ghoul", "Kaneki")]
for anime in animes:
anime.show()
#Advanced topics to study
"""
Method overriding
Abstract methods
Duck typing
Operator overloading
Runtime polymorphism
Polymorphic functions
"""