Design a class whose dimension can be set by passing 3 argument or passing single argument

Design a class whose dimension can be set by passing 3 argument or passing single argument
class box
{
private int l,b,h;
public void set(int x,int y,int z)
{
l=x;
b=y;
h=z;
}
public void set(int x)
{
l=b=h=x;
}
public void volume()
{
int v=l*b*h;
System.out.println(“volume is “+v);
}
}
class test
{
public static void main(String args[])
{
box a=new box();
box b=new box();
a.set(4,5,6);
b.set(5);
a.volume();
b.volume();
}
}

Output:
volume is 120
volume is 125

Leave a Reply

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