program ——->
class Overload
{
int volume (int x) // volume of cube
{
return (x*x*x);
}
double volume(double r, int h) // volume
//cylinder
{
return (3.14519F*r*r*h);
}
long volume(long 1, int b, int h) // volume of // rectangular
{ return (l*b*h);
}
}
class Overload Demo2
{
public static void main(String args[])
{
Overload v=new Overload();
System.out.println(“Volume of a cube = “+v.volume(10));
System.out.println(“Volume of a cylinder = “+v.volume(2.5,8));
System.out.println(“Volume of a Rectangle = “+v.volume(100L,75,15));
}
}
output —–>
D:\jaava>javac Rational. java
D:\jaava>java ObjectAsParameter
2/5 + 3/7 = 29/35
D:\jaava>
AIM: To demonstrate the Method Overloading
Name of the Experiment:
Write a java Program for to demonstrate Method Overloading – Find Volume of cube, cylinder and rectangle.
HW/SW requirements:
Processor
AMD Athelon TM 1.67 GH,
RAM
: 256 MB
Hard Disk
: 40 GB
JDK is required, with compilers, notepad
Algorithm:
- Start the program.
- Declare the class overload with variables and load the values.
- Define the methods, Overload the methods volume by using type of argument.
- End of a class.
- Start of main class
- Define the main method and create the multiple objects.
- Call the method volume on the basis of passing argument.
- End of main class.
- Compile the program.
- Run the Class file and pass the Input see the output.
- Stop the process.