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
These steps are
repeated for our
next variable,
cdBox. Note that the
1st two steps are here
collapsed into
one line:
Declaration &
Instantiation
Previous slide
Next slide
Back to first slide
View graphic version