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

Practical No 14

The document contains three Python programming exercises focused on class creation and method overloading. The first exercise involves creating a class to print an integer and a character with methods having the same name but different parameter orders. The second and third exercises involve calculating areas of geometric shapes and demonstrating inheritance with a base class and subclasses, respectively.

Uploaded by

samarthn001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Practical No 14

The document contains three Python programming exercises focused on class creation and method overloading. The first exercise involves creating a class to print an integer and a character with methods having the same name but different parameter orders. The second and third exercises involve calculating areas of geometric shapes and demonstrating inheritance with a base class and subclasses, respectively.

Uploaded by

samarthn001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No 14

X. Exercise

Que 1 - Write a Python program to create a class to print an integer and a character with
two methods having the same name but different sequence of the integer and the character
parameters. For example, if the parameters of the first method are of the form (int n, char
c), then that of the second method will be of the form (char c, int n).

class Display:
def printmsg(self,x,y):
if(type(x) ==int):
print("Integer Message :- ",x);
else:
print("Character Message :- ",x);
a = Display();
a.printmsg(20,"Shantanu A. Gaikwad")
a.printmsg("Shantanu A. Gaikwad",20)

Output –

Que 2 - Write a Python program to create a class to print the area of a square and a
rectangle. The class has two methods with the same name but different number of
parameters. The method for printing area of rectangle has two parameters which are length
and breadth respectively while the other method for printing area of square has one
parameter which is side of square.

class Rectangle:
def get(self):
self.length = int(input("Enter the length :- "))
self.breadth = int(input("Enter the breadth :- "))
class Square:
def get(self):
self.side = int(input("Enter the side :- "))
class Area(Rectangle, Square):
def showarea(self):
r1 = Rectangle()
s1 = Square()
r1.get()
s1.get()
r_area = r1.length * r1.breadth
s_area = s1.side * s1.side
print("Area of Rectangle :- ",r_area)
print("Area of Square :- ",s_area)
a1 = Area()
a1.showarea()

Output –

Que 3 - Write a Python program to create a class 'Degree' having a method 'getDegree' that
prints "I got a degree". It has two subclasses namely 'Undergraduate' and 'Postgraduate'
each having a method with the same name that prints "I am an Undergraduate" and "I am
a Postgraduate" respectively. Call the method by creating an object of each of the three
classes.

class Degree:
def getDegree(self):
print("I got a degree")

class Undergraduate(Degree):
def getDegree(self):
print("I am an Under-Graduate")

class Postgraduate(Degree):
def getDegree(self):
print("I am an Post-Graduate")

d = Degree()
d.getDegree()
u = Undergraduate()
u.getDegree()
p = Postgraduate()
p.getDegree()
Output –

You might also like