All methods in Java (also called "functions" in some other languages) must be inside a class.
Because volume
references members of box
I therefore assume it is intended to belong to box
.
class Box
{
int h,w,d;
void volume()
{
System.out.println("Volume="+(w*h*d));
}
}
Notice that I also changed box
to Box
becauses classes in Java start with an uppercase letter by convention.
Furthermore, method calls in Java end with parentheses, even if they do not take arguments:
// vv
b1.volume();
b2.volume();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…