I have created an ArrayList() and 10 Cat objects. I have even added the objects to the ArrayList(). Yet, it is showing errors.
Please, someone help.
package com.codegym.task.task06.task0614;
import java.util.*;
/*
Static cats
*/
public class Cat {
//write your code here
public static ArrayList<Cat> cats= new ArrayList<Cat>();
public Cat() {
}
public static void main(String[] args) {
//write your code here
ArrayList<Cat> cats = new ArrayList<Cat>();
Cat cat1 = new Cat();
Cat cat2= new Cat();
Cat cat3 = new Cat();
Cat cat4 = new Cat();
Cat cat5 = new Cat();
Cat cat6 = new Cat();
Cat cat7 = new Cat();
Cat cat8 = new Cat();
Cat cat9 = new Cat();
Cat cat10= new Cat();
cats.add(cat1);
cats.add(cat2);
cats.add(cat3);
cats.add(cat4);
cats.add(cat5);
cats.add(cat6);
cats.add(cat7);
cats.add(cat8);
cats.add(cat9);
cats.add(cat10);
printCats();
}
public static void printCats() {
//write your code here
Iterator itr = cats.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}