Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about anonymous inner class?

 
roger moon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would anyone shed some light on the answer D? Why is it right? I learned
from a book that "an anonymous inner class can't even extend a class and
implement an interface that the same time".

which two are true? Answer: A, D
A. An anonymous inner class can be declared inside of a method.
B. An anonymous inner class constructor can take arguments in some situations.
C. An anonymous inner class that is a direct subclass of Object can implements multiple interface.
D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface.
E. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements multipe interface.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I learned from a book that "an anonymous inner class can't even extend a class and
implement an interface that the same time".

You're right, it can't. But it can do one or the other. An anonymous class can subtype a concrete type (a class) or an interface, but not both.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic