0% found this document useful (0 votes)
5 views

MethodOverloading

The document contains two Python programs demonstrating method overloading. The first program calculates the sum of numbers using three different methods: no arguments, two arguments, and three arguments, producing outputs of 30, 210, and 100 respectively. The second program calculates the area of a rectangle, square, and circle, with user inputs resulting in areas of 156, 196, and approximately 706.95 respectively.

Uploaded by

shivani745verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

MethodOverloading

The document contains two Python programs demonstrating method overloading. The first program calculates the sum of numbers using three different methods: no arguments, two arguments, and three arguments, producing outputs of 30, 210, and 100 respectively. The second program calculates the area of a rectangle, square, and circle, with user inputs resulting in areas of 156, 196, and approximately 706.95 respectively.

Uploaded by

shivani745verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Write a Python program to find the sum of the number using


the method overloading with no argument, two arguments, and
three arguments.

Source code:
class A():
def sum(self):
a=10
b=20
c=a+b
print(c)
def sum1(self,a,b):
c=a+b
print(c)
def sum2(self,a,b,c):
d=a+b+c
print(d)
if __name__=="__main__":
obj=A()
obj.sum()
obj.sum1(10,200)
obj.sum2(5,45,50)

Output:
30
210
100
2. Write a Python program to find the Area of Rectangle, Circle, and
Square method overloading

Source code:
class A():
def rect (self):
self.l=int(input("Enter the value of l : "))
self.b=int(input("Enter the value of b : "))
area = self.l* self.b
print("Area of the rectangle :",area)
def square (self):
self.a=int(input("Enter the value of a :"))
Side_length=self.a*self.a
print("Area of the square:",Side_length)
def circle (self):
self.p = 3.142
self.r = int(input("Enter the value of r:"))
area1 = self.p*(self.r*self.r)
print("Area of the circle:",area1)
if __name__=="__main__":
obj=A()
obj.rect()
obj.square()
obj.circle()

Output:
Enter the value of l: 12
Enter the value of b: 13
Area of the rectangle: 156
Enter the value of a: 14
Area of the square: 196
Enter the value of r: 15
Area of the circle: 706.9499999999999

You might also like