
write a program to calculate volume of a cube, cylinder, rectangular box using method overloading

class Overload {
double volume(float l, float w, float h) {
return l * w * h;
}
double volume(float l) {
return l * l * l;
}
double volume(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.volume(5, 8, 9);
System.out.println("Volume of rectangular box is " + rectangleBox);
System.out.println("");
double cube = overload.volume(5);
System.out.println("Volume of cube is " + cube);
System.out.println("");
double cylinder = overload.volume(6, 12);
System.out.println("Volume of cylinder is " + cylinder);
}
}
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.