Language syntax
Java Interface declaration
Declares a common type. Interfaces have no per-instance fields or constructors; ordinary bodyless methods are public and abstract.
Formal Syntax & Structure
java syntaxjava
interface Label { String text(); }Working Example
Example Snippetjava
interface Label { String text();}class ShelfLabel implements Label { public String text() { return "Shelf A"; }}class BoxLabel implements Label { public String text() { return "Box 3"; }}public class Main { public static void main(String[] args) { Label[] labels = {new ShelfLabel(), new BoxLabel()}; for (Label label : labels) System.out.println(label.text()); }}