public interface Interface name { // abstract methods // default method // static method // private method }
final: keywords, showing the meaning of the final state, if the modification variable that becomes constant
Constant: Use public static final
Interface have default modifier constants: public static Final may be omitted
Implementation of the interface
Non-abstract subclass that implements the interface:
-
All the abstract methods in the interface must be rewritten.
-
It inherits the default interface methods that can be called directly, can also be rewritten.
class name of the class implements the interface name { // interface abstract methods must override [] // interface override the default method [optional] }
Abstract methods defined in an interface
Abstract: Method no method body, and modified using the abstract keyword
The default modifier: public abstract may be omitted
public abstract return type method name (parameter);
The default method defined in the interface - at a method thereof Method
public default return type method name (parameter) { Method member }
The definition of static methods of the interface
public static return type method name (parameter) { Method member }
Private method defined in the interface
Private non-static method
private return type method name (parameter) { Method member }
Private static method
Private static return type method name (parameter) { Method member }
Features Interface
Interface is a kind of reference data types
Interface can only define constants and methods (abstract methods, static methods, the default method, private method)
Interfaces can not define member variables and constructor
Interface not create an object can only be used by its implementation class