// use plural names for arrays and Sets Goat[] goats = new Goat[10]; // ... for ( Goat goat : goats ) { goat.feed(); } HashSet<Horse> horses = new HashSet<Horse>(10); // ... for ( Horse horse : horses ) { horse.feed(); }