1

Means, by default in Java every class extends Object class. So interface also extends Object class or not?

2
  • 1
    An interface does not extend anything. It doesn't implicitly extends Object.
    – Maroun
    Jan 2, 2014 at 10:56
  • The tag user-interface does not mean what you seem to think. Please read the helpful tag pop-ups before slapping them on your post. Jan 2, 2014 at 10:59

3 Answers 3

2

"by default in Java every class extends Object class. So interface also extends Object class or not?"

No... 1. interface can only extend another interface. in java every class extends object class (Not every interface).

If an interface has no parent, then it will IMPLICITLY have methods of the object class.

0

Reference types all inherit from java.lang.Object. Classes, enums, arrays, and interfaces are all reference types

(from http://docs.oracle.com/javase/tutorial/reflect/class/index.html).

So I think the answer is yes, it does.

-1

Can you make instances of interfaces? : No

We need concrete classes which implement the interface which also implicitly extend Object class.

Also can you call methods defined in Object class in interfaces? : No(Not directly atleast. Maybe using it as a polymorphic reference.)

Interfaces and Objects are two different concepts. You cannot mix them. If anything that is common between them is that they are in general used a polymorphic references.

As for how does the code compile when we use interface as polymorphic reference
and call Object methods on it?

An interface has one implicit method declared for each public method in Object. For more details you can refer to this question.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.