1

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Jagruttam
  • 49
  • 1
  • 1
  • 4

3 Answers3

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.

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
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.

joragupra
  • 692
  • 1
  • 12
  • 23
-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.

Community
  • 1
  • 1
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289