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.