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

PRACTICAL 14

The document contains Python programs demonstrating method overloading and inheritance. It includes a class with methods that have the same name but different parameter sequences for printing integers and characters, another class for calculating areas of a square and rectangle with methods having different numbers of parameters, and a class structure for degrees with subclasses for undergraduate and postgraduate. Each section includes example code and method calls to illustrate the concepts.

Uploaded by

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

PRACTICAL 14

The document contains Python programs demonstrating method overloading and inheritance. It includes a class with methods that have the same name but different parameter sequences for printing integers and characters, another class for calculating areas of a square and rectangle with methods having different numbers of parameters, and a class structure for degrees with subclasses for undergraduate and postgraduate. Each section includes example code and method calls to illustrate the concepts.

Uploaded by

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

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):

print("\nI got a degree")

class Undergraduate(Degree):

def dis(self):

print("\nI am a Undergraduate. ")

class Postgraduate(Degree):

def dis(self):

print("\nI am a Postgraduate. ")

obj1=Degree()

obj2=Postgraduate()

obj3=Undergraduate()
obj1.getDegree()

obj2.dis()

obj3.dis()

OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy