Polymorphism
- It is the feature of the 'one name many forms' method that can perform with different tasks.
- Polymorphism allows us to characterize methods in the child class that have similar names as the strategies in the parent class.
- One form of polymorphism is method polymorphism. That’s when the code itself implies different meanings.
- The other form is method overriding.
The types of polymorphism:
- Compile time polymorphism
- Run-time polymorphism
Program:
class bikename:
name="hero"
def function1(self):
print("bikename class executed :")
print(self.name)
class bikemodel(bikename):
model=2022
def
function2(self1):
print("bikemodel class executed:")
print(self1.model)
obj=bikename()
obj1=bikemodel()
obj.function1()
obj1.function2()
Output:
bikename class executed
hero
bikemodel class executed
2022
More topic in Python