Interfaces and Abstract Classes : Interface « Class Definition « Java Tutorial






  1. The interface should be regarded as a contract between a service provider and its clients.
  2. An abstract class is a class that cannot be instantiated
  3. An abstract class must be implemented by a subclass.
  4. In Java, the interface is a type.

Follow this format to write an interface:

accessModifier interface interfaceName {
}

public interface Printable {
         void print (Object o);
}
  1. The Printable interface has a method, print.
  2. print is public even though there is no public keyword.








5.29.Interface
5.29.1.Interfaces and Abstract Classes
5.29.2.Fields and Methods in an Interface
5.29.3.To implement an interface: use the implements keyword after the class declaration
5.29.4.A Partial Interface Implementation
5.29.5.Extending Interfaces
5.29.6.Interfaces and Multiple Inheritance
5.29.7.Interfaces and Polymorphism: Using Multiple Interfaces
5.29.8.Nesting Classes in an Interface Definition
5.29.9.Encapsulating Constants in a Program
5.29.10.Multiple interfaces
5.29.11.Initializing interface fields with non-constant initializers