You often hear that methods in an interface have no implementation. However, in Java 8 it became possible to implement the default methods.
But I'm interested. Was and is it possible to implement interface methods natively? (native
methods).
When the interview question is asked - "Is it possible to implement a method in an interface?" Answer - you can make a native method implementation, and since Java 8 it is possible to define a default method." How correct is this answer?
No, interfaces can't have native
methods:
Note that an interface method may not be declared [..] with the modifiers
final
,synchronized
, ornative
.
Technically that text is non-normative, because it only points out that this list does not contain the mentioned modifiers:
InterfaceMethodModifier:
(one of)
Annotationpublic
private
abstract
default
static
strictfp