Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
ajay solanki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi I am ajay,

Does a Interface inherit Object Class ?

I am asking becouse I saw somewhere "all classes and interface inherit Object class".

Please answer!!
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface inherits the methods of any other interfaces it explicitly extends.

But all objects extend (directly or indirectly) the Object class, so you can call Objects's methods on all objects.
 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quote
-------------------------------------------------
Does a Interface inherit Object Class ?
-------------------------------------------------

Inheritance can be implemented either in two way one is by extending some class or interfaces and second method is implementing interfaces.

Also an interface can extends other interfaces only. It can't extends or implements any class. SO Interface doesn't inherit Object class. Although all
classes are subclass of Object class,we can say that they(classes) inherit Object class.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inheritance can be implemented either in two way one is by extending some class or interfaces and second method is implementing interfaces.

Implementing an interface is not the same as inheritance, and the word "inheritance" should not be used for it.
 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ulf,
As per me,IS-A relationship show inheritance and IS-A can be implemented either by extending class/Interface or implementing Interface.

please correct me if i m wrong.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know who defines what constitutes an "IS-A relationship", but when talking about Java, implementing an interface is unrelated to inheritance. People will not understand what you're talking about.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic