This is from certification book by Kathy K. and Bert B. (Chapter 8, Q4)
which two create an anonymous inner class from within class Bar? (choose two)
A. Boo f = new Boo(24){};
B. Boo f = new Bar(){};
C. Boo f = new Boo(){String s;};
D. Bar f = new Boo(
String s){};
E. Boo f = new Boo.Bar(String s){};
Answer: B, C
Can anyone explain this. what i understand, anonymous class means no name, but these answers suggest its simply creating an instance of a class, doesn't seem like declaring a new class. It is really confusing to me.
This is the book's explanation:
"B is correct becuase anonymous inner classes are no different from any other class when it comes to
polymorphism. that means you are always allowed to declare a reference variable of the superclass type and have that reference variable refer to an instance of a subclass type, which in this case is an anonymous subclass of Bar. Since Bar is a subclass of Boo, it all works. C uses correct syntax for creating an instance of Boo."
but i didn't get where is the anonymous class.
Thanks
[ September 09, 2004: Message edited by: Barry Gaunt ]