class Box { // To declare a class named Box
double width; // To declare a double variable named width
double height; //To declare a double variable named height
double depth; // To declare a double variable named depth
// This is the constructor for Box.
Box(double w, double h, double d) { // Declare a method named Box contains three double var
width = w; // w mention to variable width
height = h; // h mention to variable height
depth = d; // depth mention to variable depth
}
// compute and return volume
double volume() { // double method named volume
return width * height * depth; this method (volume) return width * height * depth
}
}
class BoxDemo7 { // main class named BoxDemo7
public static void main(String args[]) { // main method
// declare, allocate, and initialize Box objects
Box mybox1 = new Box(10, 20, 15); /* ?????? What does it mean? Is it a method (if yes) where the parameters variables that we can pass arguments to them. Why did they put values directly? Or it is an object of a class. */
Box mybox2 = new Box(3, 6, 9); // ??????
double vol; // to declare a double variable named vol
// get volume of first box
vol = mybox1.volume();
System.out.println("Volume is " + vol);
// get volume of second box
vol = mybox2.volume();
System.out.println("Volume is " + vol);
}
}