我有一些问题。虽然我确实理解代码返回“Nothing”和 24.0 的原因,但我不太明白为什么我得到:“Nothing”24.0 AND 9.0。有人可以更好地解释这个问题吗?谢谢,这是代码。
class Object {
int w; int h; int d;
void test() { System.out.print("araferi ");}
double volum() {return w*h*d;}
void volum(double x) {
System.out.print(" "+ --x);}
}
public class Test {
public static void main (String[] args){
Object ob1=new Object();
ob1.w=2;
ob1.h=3;
ob1.d=4;
ob1.test();
ob1.volum(10);
System.out.print(" "+ob1.volum());
}
}
最佳答案
行 ob1.volum(10);
调用第二个 volum
方法,该方法递减然后打印其参数。这就是向您显示的 9.0
。
关于java - Java中的类和对象问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21538166/