OnJava8-Examples/housekeeping/ExplicitStatic.java
Bruce Eckel 49edcc8b17 reorg
2015-06-15 17:47:35 -07:00

40 lines
744 B
Java

//: housekeeping/ExplicitStatic.java
// ©2015 MindView LLC: see Copyright.txt
// Explicit static initialization with the "static" clause.
import static com.mindviewinc.util.Print.*;
class Cup {
Cup(int marker) {
print("Cup(" + marker + ")");
}
void f(int marker) {
print("f(" + marker + ")");
}
}
class Cups {
static Cup cup1;
static Cup cup2;
static {
cup1 = new Cup(1);
cup2 = new Cup(2);
}
Cups() {
print("Cups()");
}
}
public class ExplicitStatic {
public static void main(String[] args) {
print("Inside main()");
Cups.cup1.f(99); // (1)
}
// static Cups cups1 = new Cups(); // (2)
// static Cups cups2 = new Cups(); // (2)
} /* Output:
Inside main()
Cup(1)
Cup(2)
f(99)
*///:~