0% found this document useful (0 votes)
3 views1 page

Java Method Overloading Lab

The document discusses method overloading in Java, providing an example program that calculates the area of a square and a rectangle. It clarifies that method overloading requires a change in the number or type of parameters, and that constructor overloading is a form of compile-time polymorphism. The output of the example program demonstrates the correct areas calculated for both shapes.

Uploaded by

ashirimran07
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)
3 views1 page

Java Method Overloading Lab

The document discusses method overloading in Java, providing an example program that calculates the area of a square and a rectangle. It clarifies that method overloading requires a change in the number or type of parameters, and that constructor overloading is a form of compile-time polymorphism. The output of the example program demonstrates the correct areas calculated for both shapes.

Uploaded by

ashirimran07
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

Java Lab Experiment: Method Overloading

6. Output of Given Program:


30
60
31.0

7. Program to Print Area of Square and Rectangle using Method


Overloading:
class Area {

// Method to calculate area of square


void area(int side) {
[Link]("Area of Square: " + (side * side));
}

// Method to calculate area of rectangle


void area(int length, int breadth) {
[Link]("Area of Rectangle: " + (length * breadth));
}

public static void main(String args[]) {


Area obj = new Area();
[Link](5); // Square
[Link](5, 10); // Rectangle
}
}

Output:
Area of Square: 25
Area of Rectangle: 50

8. Answer:
No. The method is NOT properly overloaded if only access modifiers are different. Method
overloading requires change in number or type of parameters.

9. Answer:
Yes. Constructor overloading is one form of compile-time polymorphism.

You might also like