Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Experiment 3

Student Name: Roshan Kumar UID:20BCA1177


Branch: BCA Section/Group: 3/A
Semester:4 Date of Performance:3/8/2022
Subject Name: Internet Programing Lab Subject Code: 20CAP-255

1. Aim/Overview of the practical:


 Overloading in java
 Finding the area of shapes using overloading method

2. Task to be done:
Java Program to Find Area of Square, Rectangle, and Circle using Method Overloading

3. Algorithm/Flowchart :

I. Start
II. Declare three methods of the same name but with a different number of
arguments or with different data types.
III. Call these methods using objects.
IV. Call the corresponding methods as per the number of arguments or their
data types.
V. Display the result.
VI. Stop.

Flowchart
4. Code for experiment/practical:

//Java Program to Find the area of Square, Rectangle and Circle using
Method Overloading
public class Main
{
//Driver Code
public static void main(String[] args)
{
CalculateArea ob = new CalculateArea();
ob.area(4);
ob.area(10,12);
ob.area(5.5);
}
}
class CalculateArea
{
void area(float x)
{
System.out.println("The area of the square is "+Math.pow(x, 2)+" sq
units");
}
void area(float x, float y)
{
System.out.println("The area of the rectangle is "+x*y+" sq units");
}
void area(double x)
{
double z = 3.14 * x * x;
System.out.println("The area of the circle is "+z+" sq units");
}
}
5. Result/Output/Writing Summary:
1.Learning outcomes (What I have learnt):
1. Finding the area of squares, rectangles, and circles using method
overloading.
2. The area of the rectangle is the product of its length and
width/breadth.
3. The area of the circle is the product of the square of the radius of
the circle and the value of PI.
4. The area of the square is the square of its sides.
5. If a class has multiple methods having the same name but
different in parameters, it is known as Method Overloading.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and Performance 5
2. Worksheet 10
3. Post Lab Quiz 5

You might also like