| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
Why do we have only public static final variables in interfaces?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
Why do we have only public static final variables in interfaces?An interface defines a protocol of behavior and not how you should be implemented. A class that implements an interface adheres to the protocol defined by that interface. All fields declared within an interface are implicity public, static, and final. Why?
In general, a field declaration may include the following modifiers: public, protected, private, final, static, transient, volatile. But only public, final, and static are permitted for interface's variable. Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields. Every field in the body of an interface must have an initialization expression, which need not be a constant expression. The variable initializer is evaluated and the assignment performed exactly once, when the interface is initialized. |