public class Box{
public int length,width,height;
public int volume;
Box(int i, int j, int k){
this.length=i;
this.width=j;
this.height=k;
}
void setvolume(int i){
this.volume=i;
}
int getvolume(){
return volume;
}
}
class BigBox{
Box B1=new Box(20,30,40);
B1.length=30;
}
我创建的类盒和另一个类BigBox它将覆盖类框的对象的长度可变〜30。但是,当我写的代码B1.length = 30覆盖它,它显示了一个错误,我无法理解。谁能帮我吗?为什么在另一个类中不会覆盖类框对象的变量?
**什么**错误? – 2014-11-01 18:29:26
您不能将声明(如赋值)放在声明类成员的相同级别。 – Seelenvirtuose 2014-11-01 18:33:34
@OliverCharlesworth 像这样错误:令牌“长度”的语法错误,VariableDeclaratorId在此令牌之后预期 – aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 2014-11-01 18:37:14