The fields defined in the interface automatically have static and final properties. They cannot be "blank final," but can be initialized to a very few expressions. For example:
: Randvals.java
//Initializing interface fields with
//non-constant initializers
import java.util.*;
Public interface Randvals {
int rint = (int) (Math.random () *);
Long Rlong = (long) (Math.random () *);
float rfloat = (float) (Math.random () *);
Double rdouble = Math.random () *;
} ///:~
Because the fields are static, they are initialized after the class is first loaded, and before any fields are accessed for the first time. The following is a simple test:
: Testrandvals.java public
class Testrandvals {public
static void Main (string[] args) {
System.out.println (randvals.rint);
System.out.println (Randvals.rlong);
System.out.println (randvals.rfloat);
System.out.println (randvals.rdouble);
}
///:~
Of course, the field is not part of the interface, but is kept in the static storage area of that interface.