Re: [問題] 能否在迴圈裡面呼叫 anonymous class 的 method?
雖然不是 anonymous class,不過至少有達到你要的需求
public class Person {
public static void main(String[] args) {
class John extends Person {
protected void greeting() {
talk();
System.out.println("My Name is John");
}
}
John j = new John();
for (int i = 0; i < 5; i++) {
j.greeting();
}
}
protected void talk() {
System.out.println("Hello");
}
}
output :
Hello
My Name is John
Hello
My Name is John
Hello
My Name is John
Hello
My Name is John
Hello
My Name is John
--
We who cut mere stones must always be envisioning cathedrals.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.35.186.241
推
07/24 23:50, , 1F
07/24 23:50, 1F
→
07/25 00:44, , 2F
07/25 00:44, 2F
推
07/25 08:08, , 3F
07/25 08:08, 3F
推
07/25 09:50, , 4F
07/25 09:50, 4F
→
07/25 09:52, , 5F
07/25 09:52, 5F
推
07/25 09:55, , 6F
07/25 09:55, 6F
→
07/25 09:56, , 7F
07/25 09:56, 7F
→
07/25 09:58, , 8F
07/25 09:58, 8F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):