M
M
mamadaliev2019-05-14 13:11:52
Java
mamadaliev, 2019-05-14 13:11:52

Interfaces default to inherit from Object class in Java?

Hello!
I just started learning Java 8 and I had this question: Is the
interface inherited from the Object class by default or not?
If yes, for what purpose? You cannot create an instance of a class from an interface.
If not, then why is it said that everything is an object except primitive types?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2019-05-14
@mamadaliev

With this type of reference, you can call Object methods on the object, such as toString or hashCode.
So technically yes, it is inherited.
At a minimum, this allows such references to be stored in collections.

P
pazukdev, 2021-01-11
@pazukdev

Interfaces in Java do not inherit from Object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question