write a Java program for function overloading by creating a function of calculate of volume of a cube, cylinder and rectangular prism
Answers
Answered by
4
^_^
Here is your answer:
public class Function_Overloading
{
public static double volume (double h, double r)
{
double vcy = 22/7 * r * r * h;
return vcy;
}
public static double volume (double s)
{
double vcu = s * s * s;
return vcu;
}
public static void main (String args[])
{
double volumeCylinder = volume(24,6);
System.out.println(" Volume of the cylinder = "+ volumeCylinder);
double volumeCube = volume(64);
System.out.println(" Volume of the cube = "+ volumeCube);
}
}
Hope it helps u!
Here is your answer:
public class Function_Overloading
{
public static double volume (double h, double r)
{
double vcy = 22/7 * r * r * h;
return vcy;
}
public static double volume (double s)
{
double vcu = s * s * s;
return vcu;
}
public static void main (String args[])
{
double volumeCylinder = volume(24,6);
System.out.println(" Volume of the cylinder = "+ volumeCylinder);
double volumeCube = volume(64);
System.out.println(" Volume of the cube = "+ volumeCube);
}
}
Hope it helps u!
Similar questions
Accountancy,
7 months ago
Math,
7 months ago
English,
1 year ago
Chemistry,
1 year ago
Physics,
1 year ago