Python Overloading and Overriding
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
# Program for overloading and overrding
# class Test:
# def addition(self,a=0,b=0,c=0,d=0):
# z=a+b+c+d
# return(z)
# #calling
# T=Test()
# print(T.addition(10,20,30,40)) # 4 Arguments
# print(T.addition(10,20,30)) # 3 Arguments
# print(T.addition(10,20)) # 2 Arguments
# print(T.addition(10)) # 1 Arguments
# print(T.addition()) # 0 Arguments
# Overriding
# class Test:
# def __init__(self,a):
# print("Init with One parameter")
# def __init__(self,a,b):
# print("Init with two parameter")
# def __init__(self):
# print("Init with zero parameter")
# #calling
# T=Test()
#Overriding in inheritance
class Base:
def __init__(self):
print("Init method of Base class")
class Derived(Base):
None
# def __init__(self):
# print("Init method of Derived class")
# def __init__(self,a,b):
# print("Init method of Derived class with 2 parameter")
class Derived1(Derived):
None
# def __init__(self):
# print("Init method of Derived Derived class")
# def __init__(self,a,b):
# print("Init method of Derived one class with 2 parameter")
#Calling
#B=Base()
D=Derived1()
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

