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