import java.util.Random;
class A {
int i; // Package access
public A(int i) {
this.i = i;
}
}
public class MainClass {
private static Random rand = new Random();
private String id;
public MainClass(String id) {
this.id = id;
}
// Can be compile-time constants:
private final int VAL_ONE = 9;
private static final int VAL_TWO = 99;
// Typical public constant:
public static final int VAL_THREE = 39;
// Cannot be compile-time constants:
private final int i4 = rand.nextInt(20);
static final int i5 = rand.nextInt(20);
private A v1 = new A(11);
private final A v2 = new A(22);
private static final A v3 = new A(33);
// Arrays:
private final int[] a = { 1, 2, 3, 4, 5, 6 };
public String toString() {
return id + ": " + "i4 = " + i4 + ", i5 = " + i5;
}
public static void main(String[] args) {
MainClass fd1 = new MainClass("fd1");
fd1.v2.i++;
fd1.v1 = new A(9);
for (int i = 0; i < fd1.a.length; i++)
fd1.a[i]++;
System.out.println(fd1);
System.out.println("Creating new FinalData");
MainClass fd2 = new MainClass("fd2");
System.out.println(fd1);
System.out.println(fd2);
}
}
fd1: i4 = 15, i5 = 5
Creating new FinalData
fd1: i4 = 15, i5 = 5
fd2: i4 = 15, i5 = 5