0% found this document useful (0 votes)
2 views2 pages

Task- Polymorphism in Python

The document outlines four Python programs demonstrating polymorphism and method overloading. The first program is a Calculator class that adds two or three numbers using default arguments, while the second program calculates the area of shapes based on the number of arguments. The third and fourth programs showcase a payment gateway system and an employee bonus system, respectively, using polymorphism to handle different payment methods and bonus calculations for various employee types.

Uploaded by

ankitajadhv039
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)
2 views2 pages

Task- Polymorphism in Python

The document outlines four Python programs demonstrating polymorphism and method overloading. The first program is a Calculator class that adds two or three numbers using default arguments, while the second program calculates the area of shapes based on the number of arguments. The third and fourth programs showcase a payment gateway system and an employee bonus system, respectively, using polymorphism to handle different payment methods and bonus calculations for various employee types.

Uploaded by

ankitajadhv039
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/ 2

🔁 Polymorphism in Python

Program 1: Calculator – Method Overloading using Default Arguments

Problem Statement:
Create a class Calculator with a method add() that can add two or three numbers using default
arguments.
Simulate function overloading by calling the same method with different number of arguments.

Sample Output:

Addition of 2 numbers: 9

Addition of 3 numbers: 15

*Program 2: Area Calculation – Method Overloading using args

Problem Statement:
Create a class Area with a method calculate() using *args.

• If 1 argument → calculate area of square

• If 2 arguments → calculate area of rectangle

• If 3+ arguments → display error message

Sample Output:

Area of Square: 25

Area of Rectangle: 24

Invalid number of arguments

Program 3: Payment Gateway System

Problem Statement:
Design a payment system using polymorphism.
Create a base class Payment with a method make_payment().
Override this method in subclasses: CreditCard, DebitCard, and UPI.
Each subclass processes the payment in its own way.

Sample Output:

Processing ₹500 payment using Credit Card.

Processing ₹300 payment using Debit Card.

Processing ₹150 payment via UPI (Google Pay, PhonePe).


Program 4: Employee Bonus System

Problem Statement:
Build a bonus calculation system using polymorphism.
Create a base class Employee with a method get_bonus().
Override this method in subclasses: Manager, Developer, and Intern.
Return different bonuses based on employee type.

Sample Output:

Manager gets a bonus of ₹20000

Developer gets a bonus of ₹10000

Intern gets a bonus of ₹3000

You might also like