Monday, 22 August 2011

A JAVA PROGRAM SHOWING OBJECTS AND ITS CLASS IMPLEMENTATION


HERE WE HAVE BOX AS A CLASS WITH WIDTH,HEIGHT AND DEPTH AS ATTRIBUTES AND VOLUME AS METHOD.PROGRAM IS SELF EXPLAINATORY.
class box
{
double width;
double height;
double depth;

public void volume()
{
System.out.println("volume is ");
System.out.println(width*height*depth);
}
}
class boxdemo
{
public static void main(String args[]){
box mybox1=new box();
box mybox2=new box();
mybox1.width=100;
mybox1.height=20;
mybox1.depth=10;
mybox2.width=3;
mybox2.height=6;
mybox2.depth=7;
mybox1.volume();
mybox2.volume();
}
}

No comments:

Post a Comment