class Box
{
private double width, height, depth;
double volume()
{
double vol = width*height*depth;
return vol;
}
Box(double w, double h, double d)
{
width=w;
height=h;
depth=d;
}
Box()
{
width = -1;
height = -1;
depth = -1;
}
Box(double len)
{
width=height=depth=len;
}
Box(Box ob)
{
width = ob.width;
height = ob.height;
depth = ob.depth;
}
}
class BoxDemo
{
public static void main(String[] args)
{
Box b1 = new Box(10,20,15);
Box b2 = new Box();
Box b3 = new Box(5);
Box b4 = new Box(b1);
double vol;
vol = b1.volume();
System.out.println(vol);
vol = b2.volume();
System.out.println(vol);
vol = b3.volume();
System.out.println(vol);
vol = b4.volume();
System.out.println(vol);
}
}
OUTPUT
Comments
Post a Comment