Python Encapsulation

Polymorphism means same function name (but different signatures) being uses for different types

Exmaples

lst =[2,5,7,8] print(len(lst)) //output 4 mstr ='krishna' print(len(mstr)) //output 7

As len function receive the diffent types data list, string (signature) and len function is same but return length for both so this is called polymorphism

Method Overloading

-: Method overloading is one concept of polymrphism
-: Its comes under the elements of OOPS.
-: It is worked in the same method names and different arguments.
-: Arguments diffent will be based on a number of argments and types of arguments.

Example

class Area: def find_area(self,a=None,b=None): if a!=None and b!=None: print("Area of Retangle:", (a*b)) elif a!=None: print("Area of Square:", (a*a)) else: print("Nothing found") obj = Area() obj.find_area(4) obj.find_area(4,6)

Method Overriding

-: Method overriding is the method having the same name with the same arguments
-: It is implemented with Inheritance also.
-: It mostely use for memory reducing process

Example

class A: def showdata(self): print('I am A') class B(A): def showdata(self): print('I am B') obj = B() obj.showdata() # parent method name has been overrite by child class name so this is overriding

X