+ 7
What modifiers are allowed for methods in an interface ?
3 Respostas
+ 12
Only public and abstract modifiers are allowed for methods in interfaces.
+ 9
With the release of Java 8, the authors have introduced two new types of methods to an interface: default and static methods.
A default method is a method defined within an interface with the 'default' keyword in which a body method is provided. Clases that implement an interface may then override this default implementation, but may also use the default by not implementing the method at all.
A default method may only be declared with in an interface and not with in a class or abstract class.
Like all methods in an interface, a default method is assumed to de public and will not compile if marked as private or protected.
Java 8 also includes support for static methods within interfaces.
To reference the static method, a reference to the name of the interface must be used. For example: NameOfInterface.getMethod()
Because you need to provide the name of the interface in order to use a static method, implementing multiple interfaces which have static methods with the same signature will still compile.
All abstract, default and static methods in an interface are implicitly public, so you can omit the public modifier.
0
when sup class declares