[問題] 求助inner class
剛剛碰到個關於inner class的問題..求解~__~"
像是這樣...
public class test {
public class person {
private String name;
public person() {
this("noname", 0);
}
public person(String name, int money) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("test.in"));
int NP = Integer.parseInt(f.readLine());
person[] pe = new person[NP];
for (int index = 0; index < NP; index++) {
pe[index] = new person();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
會有錯誤:No enclosing instance of type test is accessible. Must qualify the allocation
with an enclosing instance of type test (e.g. x.new A() where x is an
instance of test).
}
System.exit(0); // don't omit this!
}
}
不知道該怎麼解決= ="..把person class放在外面就沒這個問題,弄來裡面就會這樣 ..
咕狗過有看到不能這樣宣告,想請問一下這樣該怎麼解決嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.39.170.147
→
03/12 18:01, , 1F
03/12 18:01, 1F
推
03/12 18:02, , 2F
03/12 18:02, 2F
→
03/12 18:03, , 3F
03/12 18:03, 3F
→
03/12 18:09, , 4F
03/12 18:09, 4F
→
03/12 18:15, , 5F
03/12 18:15, 5F
→
03/12 18:17, , 6F
03/12 18:17, 6F
→
03/12 18:30, , 7F
03/12 18:30, 7F
→
03/12 18:31, , 8F
03/12 18:31, 8F
→
03/12 19:07, , 9F
03/12 19:07, 9F
→
03/13 23:02, , 10F
03/13 23:02, 10F
討論串 (同標題文章)