J
J
Jake Taylor2020-07-28 16:07:55
Java
Jake Taylor, 2020-07-28 16:07:55

Can an interface method have a body in Java?

I recently had an interview.
When asked what an interface is, I answered that "it is a collection of abstract classes that do not have a body."
To this they said that a method in the interface can have a body from some version of Java, but they don’t remember which one.
Is it so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-07-28
@n199a

Yes
https://javarush.ru/groups/posts/1984-defoltnihe-m...

P
pazukdev, 2021-01-10
@pazukdev

Body can (and must) have static, default (Java 8), and private (Java 9) methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question