Polymorphism in Python is allows to make different form same method name but different parameter.It is two divided into two part method overriding method overloading.
In method overloading, class has two or more methods with same name but with different parameter list is known as method overloading.it is the signature of methods must be different but the return type can be same or different.
Syntaxclass mainclass: def main1(parameter1,parameter2): #statement def main1(parameter2,parameter1): #statement -----------------------------or-------------------------------------- class mainclass: def main1(parameter1,parameter2): #statement def main1(parameter3,parameter4) #statementNote
If the parameter same name but different datatype,then both parameter are different.
Exampleclass parent: def parentclass(self,x,y,z): print("Sum1=",self.x+self.y+self.y) class child(parent): def parentclass(self,x,y): print("sum2=",x+y) obj1=parent() obj1.parentclass(4,8,13)
Vikas Chaurasiya
In medod overriding,declaration of a method in sub class which is already present in parent class is known as method overriding. Overriding is done so that a child class can give its own implementation to a method which is already provided by the parent class. In this case the method in parent class is called overridden method and the method in child class is called overriding method.
Syntaxclass mainclass: def main1(parameter1,parameter2): #statement def main1(parameter2,parameter1): #statementExample
class parent: def parentclass(self): print("This is Parent1 Class") class child(parent): def child1class(self): print("This is child1 Class") class child1(child): def child1class(self): print("This is child1 Class") class child2(child): def child2class(self): print("This is child2 Class") obj1=child1() obj1.parentclass() obj2.parentclass()
This is Parent1 Class This is Parent1 Class