Interface (Java)

An interface in the Java programming language is an abstract type that is used to declare a behavior that classes must implement.

Starting with Java 8, default[1]: 99  and static[1]: 7  methods may have implementation in the interface definition.

The call whistler.whistle() will call the implemented method whistle of object whistler no matter what class it has, provided it implements Whistler.

In a more practical example, a sorting algorithm may expect an object of type Comparable.

Since the interface specifies a set of exposed behaviors, all methods are implicitly public.

Classes can implement multiple interfaces: Interfaces can share common class methods: However a given class cannot implement the same or a similar interface multiple times: Interfaces are commonly used in the Java language for callbacks,[4] as Java does not allow multiple inheritance of classes, nor does it allow the passing of methods (procedures) as arguments.

Predator and Venomous may possibly define or inherit methods with the same signature, say kill(Prey p).