• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does an interface extend Object class? If not, how come the equals() method is available?  RSS feed

 
phooton misra
Ranch Hand
Posts: 52
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

as by default any java class will extend object class,similarly interface does it extend object class?
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces cannot be instantiated. If you have a reference to an object that IS-A Interface type then that object is an instance of a class that implements that interface (or one of its super classes implements it).

All Classes inherit from Object (either directly or indirectly), so all Classes have the equals method. All object references are instances of concrete classes, so you can call equals on any object reference, even if the type of your variable is an Interface type.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way Mike describes it is probably the best way to think about it, but the Java Language Specification does actually say that any interface without a superinterface will implicitly declare member methods that match each public member method of the Object class.
 
phooton misra
Ranch Hand
Posts: 52
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Thompson....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!