
calculate volume of cube, cylinder and rectangular box using method overloading in java

calculate volume of cube, cylinder and rectangular box using method overloading in java

Hope this will help you :
class Overload {
double area(float l, float w, float h) {
return l * w * h;
}
double area(float l) {
return l * l * l;
}
double area(float r, float h) {
return 3.1416 * r * r * h;
}
}
public class MethodOverloading {
public static void main(String args[]) {
Overload overload = new Overload();
double rectangleBox = overload.area(5, 8, 9);
System.out.println("Area of ractangular box is " + rectangleBox);
System.out.println("");
double cube = overload.area(5);
System.out.println("Area of cube is " + cube);
System.out.println("");
double cylinder = overload.area(6, 12);
System.out.println("Area of cylinder is " + cylinder);
}
}
It's output is :
Area of ractangular box is 360.0 Area of cube is 125.0 Area of cylinder is 1357.1712

thank you,,,,,:)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.