Why doesn't this code work?
Everytime i make a new object, constructor shud add this object to arrayList? Right? So why program tells me "Main method does not add all objects to your list"?
package pl.codegym.task.task06.task0614;
import java.util.ArrayList;
/*
Statyczne koty
*/
public class Kot {
public static ArrayList<Kot> koty = new ArrayList<Kot>();
public Kot() {
koty.add(this);
}
public static void main(String[] args) {
for(int i = 0; i < 10; i++) new Kot();
printKoty();
}
public static void printKoty() {
for(Kot kotDoDruku: koty) System.out.println(kotDoDruku);
}
}