Classes/Objects  «Prev 


Java Inner interfaces

The release of JDK 1.1 also introduced inner interfaces, which are interfaces that are defined inside other classes or interfaces. However, unlike inner classes, inner interfaces are seldom used. Since interfaces are not associated with an object instance, they are always static. Likewise, any class that is declared within an interface is also static.

Valid Access Modifiers for Members of an Interface

All members of an interface,
  1. variables,
  2. methods,
  3. inner interfaces, and
  4. inner classes
(an interface can define a class within it), are public by default.
Interfaces support only the public access modifier. Using other access modifiers results in compilation errors.

interface MyInterface {
 private int number = 10;
 protected void aMethod();
 interface interface2{}
 public interface interface4{}
}

The code at B fails compilation with the following error message:
illegal combination of modifiers: public and private
private int number = 10;
SPECIAL CHARACTERISTICS OF METHODS AND VARIABLES OF AN INTERFACE


Every field inside an interface is implicitly public, static, and final.
In this case WebConstants declares an inner interface (public, static, and final) Framework and (public, static, and final) Look which have also some (public, static, and final) String fields.
This is a (not very common) way to order constants in your code, with this structure you could type:
String action = WebConstants.Framework.ACTION; 
String list = WebConstants.Look.LIST_CONT; 
The advantage of this is that since the WebConstants is an interface you can not accidentally instantiate it.