PPT Slide
Using Objects: Creating a Box
class BoxesExample {
public static void main (String[ ] argv) {
Box shoeBox;
shoeBox = new Box( );
shoeBox.setLength(35);
shoeBox.setWidth(19);
shoeBox.setHeight(13);
Box cdBox = new Box( );
cdBox.setLength(14);
cdBox.setWidth(9);
cdBox.setHeight(1);
int iTotalVolumeOfBoxes;
iTotalVolumeOfBoxes =
shoeBox.getVolume()
+ cdBox.getVolume();
System.out.println
(“The combined volume of the boxes”);
System.out.println
(“is: “, iTotalVolumeOfBoxes);
} // of main
} // of class BoxesExampleProgram
A second class is used
to create an instance
of our box class.
The BoxesExample
class has a main
method, and is run
as a program
Previous slide
Next slide
Back to first slide
View graphic version