Java 8 extends the declaration of the interface with the two new concepts of the default method and the static method.
Public Interface inte{ void method (); void Defaultmethod () { System.out.println ("Default"); } Static void Staticmehod () { System.out.println ("Static");} }
public static void Main (String[]args) {
Inte.staticmehod (); Static
}
Private Interfacedefaulable { defaultString notrequired () {return"Default Implementation"; } } Private Static classDefaultableimplImplementsdefaulable {}Private Static classOverridableimplImplementsdefaulable {@Override PublicString notrequired () {return"Overridden Implementation"; }}
The Defaulable interface declares a default method notrequired () with the keyword default, and one of the Defaulable interface implementations Defaultableimpl implements the interface and keeps the default method intact. Another implementation of the Defaulable interface Overridableimpl overrides the default method in its own way.
java8-new Features-(default and static methods for interfaces)