- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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); }
- Related Articles
- Final static variables in Java
- Static and non static blank final variables in Java
- Why variables are declared final in Java
- What is blank final variable? What are Static blank final variables in Java?
- Assigning values to static final variables in java
- Difference between default and static interface method in Java 8.
- Why are global and static variables initialized to their default values in C/C++?
- Default method vs static method in an interface in Java?
- Can we initialize static variables in a default constructor in Java?
- Do static variables get initialized in a default constructor in java?
- Can we create non static variables in an interface using java?
- Default values of static variables in C
- Difference Between Static and Final in Java
- final variables in Java
- Are static local variables allowed in Java?

Advertisements