My code as attached prints the hashCode for each object, 1 per line, but this doesn't meet the requirements. I'm trying to override the toString() method to correct this. But (after un-commenting lines 16-19), whatever I try to return causes an error. How do I fix this?
package com.codegym.task.task06.task0614;
import java.util.ArrayList;
/*
Static cats
*/
public class Cat {
//write your code here
public static ArrayList<Cat> cats = new ArrayList<Cat>();
public Cat() {
}
//@Override
//public String toString() {
// return cats.get(i);
//}
public static void main(String[] args) {
//write your code here
for(int i = 1; i<=10; i++) {
Cat.cats.add(new Cat());
//Cat cat = new Cat();
//Cat.cats.add(cat);
//System.out.println(Cat.cats.size()); //confirm no. of objects in ArrayList
//System.out.println(cat);
}
printCats();
}
public static void printCats() {
//write your code here
for(int i = 1; i<cats.size(); i++) {
//for(Cat cat: cats) {
System.out.println(cats.get(i));
}
}
}