Java Program For Finding Volume Using constructing box with 3 params

class Box
{
 double width;
 double height;
 double depth;
        
       

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

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

 

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

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

double vol;

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

vol=mybox2.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