类的构造函数到底是在什么时间被调用的??
Anol 2003-10-15 10:18:32 对象被创建时?还是在调用对象时??
如下代码的执行结果??
class Box {
double width,height,depth;
Box() {
width=10;
height=3;
depth=2;
}
double volume(){
System.out.println("Constructing Box....");
return width*height*depth;
}
}
class BoxDemo6 {
public static void main(String args[]) {
Box mybox1=new Box();
Box mybox2=new Box();
double vol;
vol=mybox1.volume();
System.out.println("Volume is "+vol);
vol=mybox2.volume();
System.out.println("Volume is "+vol);
}
}