Java Program For Finding Volume Using 3 Parameters

class Box
{
 double width;
 double height;
 double depth;
        
        Box(double w, double h, double d)
 {
          System.out.println("constructing box with 3 params"); 
         width=w;
         height=h;
         depth=d;
        }

        Box(double w, double h)
 {
          System.out.println("constructing box with 2 params"); 
         width=w;
         height=h;
         depth=10;
        }

 Box(double w)
 {
          System.out.println("constructing box with 1 param"); 
         width=w;
         height=5;
         depth=10;
        }

 double volume()
 {
         return width*height*depth;
 
 }
        
}

class BoxDemoCon5
{
public static void main(String args[])
{
Box mybox1= new Box(10,20,15);
Box mybox2= new Box(3,6);
Box mybox3= new Box(3);

double vol;

vol=mybox1.volume();
 System.out.println(" Volume is " + vol); 

vol=mybox2.volume();
 System.out.println(" Volume is " + vol); 
 
vol=mybox3.volume();
 System.out.println(" Volume is " + vol);
}
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment