Interfaces
Another way to achieve abstraction in Java, is with interfaces.
An interface
is a completely “abstract class” that is used to group related methods with empty bodies:
Example
// interface
interface Animal {
public void animalSound(); // interface method (does not have a body)
public void run(); // interface method (does not have a body)
}
To access the interface methods, the interface must be “implemented” (kinda like inherited) by another class with the implements
keyword (instead of extends
). The body of the interface method is provided by the “implement” class: Continue reading Java Interface