...
Code Block |
---|
|
public class Cycle {
private final int balance;
private static final Cycle c = new Cycle();
private static final int deposit = (int) (Math.random() * 100); // Random deposit
public Cycle() {
balance = deposit - 10; // Subtract processing fee
}
public static void main(String[] args) {
System.out.println("The account balance is: " + c.balance);
}
}
|
The Cycle()
class declares a private static final
class variable which is initialized to a new instance of the Cycle()
class. Static initializers are guaranteed to be invoked once before the first use of a static class member or the first invocation of a constructor.
...
Code Block |
---|
|
class A {
public static public final int a = B.b + 1;
// ...
}
|
Code Block |
---|
|
class B {
public static public final int b = A.a + 1;
// ...
}
|
...
Code Block |
---|
|
class A {
public static public final int a = 2;
// ...
}
// class B unchanged: b = A.a + 1
|
...