Which construct an anonymous inner class instance? (Choose all that apply.)
A. Runnable r1 = new Runnable() { };
B. Runnable r1 = new Runnable(public void run() { });
C. Runnable r1 = new Runnable { public void run(){}};
D. Runnable r1 = new Runnable() {public void run{}};
E. System.out.println(new Runnable() {public void run() { }});
F. System.out.println(new Runnable(public void run() {}));
A cannot be since run should be public.....B not since ( is there instead of {....C is wrong too since runnable whould be runnable()....D is wrong since run should be run()...definitely not F
am not sure about E....maybe ; is missing..i think it should be System.out.println(new Runnable() {public void run() { }};);
I thought in the same way as you Ankur, but in k&B book page no.659 chapter 8(SCJP 5), the answer to this problem is given E.
When i tried to comile it using option E It gives compilation error in println statement.
Is it bug in the book??