class TryInitialization {
static int[] values = new int[10];
{
System.out.println("Running initialization block.");
for (int i = 0; i < values.length; i++)
values[i] = (int) (100.0 * Math.random());
}
void listValues() {
System.out.println();
for (int i = 0; i < values.length; i++)
System.out.print(" " + values[i]);
System.out.println();
}
public static void main(String[] args) {
TryInitialization example = new TryInitialization();
System.out.println("\nFirst object:");
example.listValues();
example = new TryInitialization();
System.out.println("\nSecond object:");
example.listValues();
}
}
|