Interfaces
suggest changeIntroduction
An interface is a reference type, similar to a class, and is declared with the interface keyword.
Interfaces can contain constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Java 9 also allows private methods. Like abstract classes, interfaces cannot be instantiated. They can only be implemented by classes or extended by other interfaces.
An interface can describe a type without instance fields. Default methods mean it is not only a list of abstract methods.
Syntax
- public interface Foo { void foo(); /* any other methods */ }
- public interface Foo1 extends Foo { void bar(); /* any other methods */ }
- public class Foo2 implements Foo, Foo1 { /* implementation of Foo and Foo1 */ }
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents