Interface variables are static and final by default in Java, Why?

An interface defines a protocol of behavior and not how we should be implemented. A class that implements an interface adheres to the protocol defined by that interface.

  • Interface variables are static because java interfaces cannot be instantiated on their own. The value of the variable must be assigned in a static context in which no instance exists.
  • The final modifier ensures the value assigned to the interface variable is a true constant that cannot be re-assigned. In other words, interfaces can declare only constants, not instance variables.

Template :

interface interfaceName{
   // Any number of final, static variables
   datatype variableName = value;
   // Any number of abstract method declarations
   returntype methodName(list of parameters or no parameters);

Updated on: 11-Feb-2020

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started