我希望它返回新的 Dillo 并打印出新 Dillo 的长度。当我编译代码时,它会说:错误:该行的代码无法访问System.out.println(this.length);
我该如何解决这个问题?谢谢
import tester.* ;
class Dillo {
int length ;
Boolean isDead ;
Dillo (int length, Boolean isDead) {
this.length = length ;
this.isDead = isDead ;
}
// produces a dead Dillo one unit longer than this one
Dillo hitWithTruck () {
return new Dillo(this.length + 1 , true) ;
System.out.println(this.length);
}
}
class Examples {
Examples () {} ;
Dillo deadDillo = new Dillo (2, true) ;
Dillo bigDillo = new Dillo (6, false) ;
}