Basics

Design a class to overload a function volume( ) , Function Overloading based second program

Design a class to overload a function volume( ) , Function Overloading based second program

import java.io.*;
import java.util.*;

class Overloaded
{
	double volume( double R )
	{
		double vol = 4/3*22/7*R*R*R;
		return vol;
	}
	double volume( double H, double R )
	{
		double vol = 22/7*R*R*H;
		return vol;
	}
	double volume( double L, double B, double H )
	{
		double vol = L*B*H;
		return vol;
	}
  public static void main(String args[ ])
  {
  	Scanner sc = new Scanner(System.in);
  	Overloaded ob = new Overloaded( );
  	System.out.println("Volume of Sphere ="+ob.volume( 6.4 ));
  	System.out.println("Volume of Cylinder ="+ob.volume( 8.2, 3.9 ));
  	System.out.println("Volume of Cuboid ="+ob.volume( 5.3, 4.5, 8.6 ));
  }
}

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top