- Code: Select all
//use of constructors
class shape
{
int l,b,h;
shape()//DEAFULT CONSTRUCTORS
{
l=1;
b=1;
h=1;
}
shape(int x,int y,int z)//PARAMETERIZED CONSTRUCTOTS
{
l=x;
b=y;
h=z;
}
float volume()
{
return l*b*h;
}
}
class vol
{
public static void main(String ar[])
{
float a1;
shape s1=new shape();
a1=s1.volume();
System.out.println(a1);
shape s2=new shape(4,5,6);
a1=s2.volume();
System.out.println(a1);
}
}