Thursday, 21 June 2012

constructor in java Example


constructor in java Example 



class box
{
double width;
double height;
double length;

box(double w,double h,double l)
{
width=w;
height=h;
length=l;
}
double volume()
{
return width*height*length;
}
}
class boxdemo
{
public static void main(String args[])
{
box b1=new box(10,20,30);
box b2=new box(3,6,9);
double vol;
vol=b1.volume();

System.out.println(vol);
vol=b2.volume();

System.out.println(vol);
}

}

No comments:

Post a Comment