Skip to content

Interface

Keyhan Hadjari edited this page Sep 18, 2016 · 1 revision
  • Interfaces can be _public _ or default access.
  • Cannot be instantiated.
  • Interfaces are Always abstract.
  • Can be empty
  • Cannot be final
  • A class may implement multiple interfaces.
  • An interface can extend Another interface.
  • Methods in an interface are Always public abstract
  • First Concrete class that implements an interface has to implement all of its inherited abstract methods.
  • An abstract class inherits methods of the interface it is extending, but it does not have to implement them.

Interface variables

  • Always public, static and final.
  • Value has to be set when declared in the interface.

Default interface method (java 8)

  • a method defined in the interface body.
  • Use default keyword.
  • The class may override the default method.
  • Allows backwards compatibility since default methods are not needed to be implemented in the class implementing the interface. Allows libraries to be updated without affecting the code.
  • Only in interface and is public.
  • If same default method is defined in two interfaces implemented in a class, then compilation would fail.

Static interface method (java 8)

  • Is implemented in the interface
  • Is not inherited in any class implementing the interface
  • Is public
  • The name of the interface has to be used to access the method.

Clone this wiki locally