1 回答

TA貢獻1828條經(jīng)驗 獲得超3個贊
該類Security繼承了屬性row和colfrom Position,但在構(gòu)造函數(shù)中,您正在執(zhí)行以下操作:
Security() {
int row = 3; //you are basically creating a new variable called row
int col = 2; //which is NOT the attribute (that is this.row)
character = 'S';
}
在構(gòu)造函數(shù)之后,Security對象保持s.row等于s.col0。
你應(yīng)該做
Security() {
this.row = 3; //you can also do row = 3;
this.col = 2; //and the compiler will understand
this.character = 'S';
}
你在 中犯了同樣的錯誤Donald:你告訴Donald要在位置 (0,0) 但然后你告訴Security要在位置 (0,0),這就是為什么Security出現(xiàn)但Donald沒有出現(xiàn),他被覆蓋了Security。
Player正如您所設(shè)置的,它位于第 4 行第 2 列。
添加回答
舉報