This is an example method overloading in Java to write a program to find the area of a rectangle, a triangle and a square.
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);
}
}
This example was submitted to Rose India - a website where you can find many Java scripts and also examples of how to develop Java Scripts.
Java script is great because it gives us the ability to write any kind of computer program, but the main downside comes from the fact that it is so difficult to learn and create.
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);
}
}
This example was submitted to Rose India - a website where you can find many Java scripts and also examples of how to develop Java Scripts.
- Java Script
Java script is great because it gives us the ability to write any kind of computer program, but the main downside comes from the fact that it is so difficult to learn and create.