Java Language -- Interfaces - Overview
An interface specifies a collection of methods (behaviors) without implementing their bodies (akin to giving the API).
- public interface Storable {
- public abstract void store(Stream s);
- public abstract void retrieve(Stream s);
- }
Any other class which implements the interface is guaranteeing that it will have the set of behaviors, and will give concrete bodies to the methods of the interface.
Interfaces solve some of the same problems as multiple inheritance, without as much overhead at runtime.
- There is a small performance penalty because interfaces involve dynamic method binding.
Interfaces can be implemented by classes on unrelated inheritance trees, making it unnecessary to add methods to common superclass.