class Math{
static int count = 0;
static {
System.out.println(++count);
}
}
class Position{
static {
System.out.println(++Math.count);
}
}
public class Example {
public static void main(String args[]) {
Math ref1 = new Math(); // wyświetli 1
Position ref2 = new Position(); // wyświetli 2
Math ref3 = new Math(); // tutaj już nic nie wyświetla
Position ref4 = new Position(); // tutaj już nic nie wyświetla
}
}
eee, dlaczego nie zlicza każdego nowo powstałego obiektu? myślałem że w taki sposób wyświetli 4 a na wyjściu wyświetliła mi się tylko 1 i 2