• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification regarding Interfaces  RSS feed

 
prabal nandi
Greenhorn
Posts: 28
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As in java every object is extended from the Object class. Can any one tell me whether interfaces are also extended from Object or not, if not then why?
and what will be the superclass of interfaces??
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, interfaces do not extend Object. Interfaces can only extend other interfaces, not regular classes. Since Object is a class (not an interface), interfaces cannot extend Object.

But you can't create an instance of an interface. You can only create instances of classes. And since Object is the superclass of all classes, you know that when you have an object, it always has the methods that are available in class Object.
 
prabal nandi
Greenhorn
Posts: 28
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in the interface hierarchy what will at the top most position???
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your interface doesn't explicitly extend another interface, then your interface is itself at the top of the inheritance hierarchy. Interfaces don't have an implicit top-level interface in the same way that all classes implicitly extend class Object.
 
prabal nandi
Greenhorn
Posts: 28
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was very helpful.. thanks a lot
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!