Dear all,
on page 481 of the K&B book there is question #3:
...
3. Which constructs an anonymous inner class instance?
A. Runnable r = new Runnable() { };
B. Runnable r = new Runnable(public void run() { });
C. Runnable r = new Runnable { public void run(){}};
D. Runnable r = new Runnable() {public void run{}};
E. System.out.println(new Runnable() {public void run() { }});
F. System.out.println(new Runnable(public void run() {}));
The answer to this question is:
3. E is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, so it must override the run() method of Runnable.
A is incorrect because it doesn’t override the run() method, so it violates the rules of interface implementation. B, C, and D use incorrect syntax.
Shouldn't it be C
