GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface" Watch "interface" New topic
Author

interface

ajay solanki
Ranch Hand

Joined: Feb 25, 2008
Posts: 37
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
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.


Ping & DNS - my free Android networking tools app
Prabhat Gupta
Ranch Hand

Joined: Jan 22, 2008
Posts: 135
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
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

Joined: Jan 22, 2008
Posts: 135
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
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: interface