Interfaces

Cards (11)

  • An Interface in Java programming language is defined as an abstract type used to specify the behavior of a class.
  • An interface in Java is a blueprint of a class.
  • A Java interface contains static constants and abstract methods.
  • Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, no body).
  • Interfaces specify what a class must do and not how. It is the blueprint of the class.
  • An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.
  • If a class implements an interface and does not provide method bodies for all functions specified in the interface, then the class must be declared abstract.
  • Interface is used to achieve total abstraction.
  • Since java does not support multiple inheritances in the case of class, by using an interface it can achieve multiple inheritances.
  • Interface is also used to achieve loose coupling.
  • Interfaces are used to implement abstraction.