JAVA PROGRAM ON OBJECTS AND ITS CLASS

itprofessionalsrocks.blogspot.com
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();
}
}

Comments

Popular posts from this blog

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)