• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about anonymous inner class?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic