• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Anonymous classes

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I wonder if questions like this can appear in the main exam

An anonymous class implementation can implement only one interface. But if that inteface extends any other interfaces then the anonymous class should implement those interfaces also.

so if there is a question which says that "anonymous classes can implement only one interface or can extend only one class" will this statement be true or false

-Sharanya
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that this is a true statement. When you declare an anonymous class, it can extend only one class or implement only one interface directly. In essence, an anonymous class always extends at least one class (Object), in addition to any interface it might implement.

I would hope that, on the actual SCJP exam, this would be worded carefully as to not confuse you. It seems you have a good understanding of the principles involved - I wouldn't be concerned.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be true.

This is most clearly seen when thinking about classes - we don't say that java.util.ArrayList extends three classes, simply because it extends AbstractList which extends AbstractCollection which extends Object. We say that, in Java, a class can extend only one class (single implementation inheritance). That one class implies all its ancestors as well.

- Peter
 
Don't listen to Steve. Just read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic