• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Java OCP 8 Programmer II Study Guide (Sybex Ch 1 - p30)

 
Greenhorn
Posts: 4
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following paragraph is taken from Java OCP 8 Programmer II Study Guide (Sybex Ch 1 - p30) from Jeanne boyarsky

"But what if we want to implement both an interface and extend a class? You can’t with an anonymous inner class, unless the class to extend is java.lang.Object. Object is a special class, so it doesn’t count in the rule."

Q. How can we  both implement an interface and extend a class from java.lang.Object? How does not Object class count in the rule? Please explain through example.
 
Marshal
Posts: 65467
249
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes implicitly extend Object. You cannot writeThe Java® Language Specification (=JLS) says,

. . . The superclass or superinterface of an anonymous class is given by the class instance creation expression . . .

So what is that class' immediate supertype? Is it Foo or Bar? If you write extends in an anonymous class declaration, you are risking giving the class two superclasses, and as you know, two superclasses are not permissible. extends
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!