PRACTICAL 14
PRACTICAL 14
'''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 A:
def dis(self,n,c):
print("Integer n:",n)
print("Character c:",c)
def dis(self,c,n):
print("Character c:",c)
print("Integer n:",n)
obj = A()
obj.dis(42,'A')
obj.dis('B',23)
"""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 area:
def cal(self,s):
s=int(a)
print("Area of Square:",s*s)
def cal(self,l,b):
print("\nArea of Rectangle:",l*b)
obj1=area()
obj1.cal(5,4)
'''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):
class Undergraduate(Degree):
def dis(self):
class Postgraduate(Degree):
def dis(self):
obj1=Degree()
obj2=Postgraduate()
obj3=Undergraduate()
obj1.getDegree()
obj2.dis()
obj3.dis()
OUTPUT:-