I made a method that makes a list and fills it with "Dog" objects using FOR loop, and at the end prints the stuff that's in the list. However, when I run it, instead of printing the Strings it prints something weird like " list.Dog@eed1f14 "
public class Dog {
private String breed;
private String name;
Scanner s = new Scanner(System.in);
public void makeList(){
System.out.println("What's ths size of the list?");
int sizeOfList = s.nextInt();
List<Dog> dog = new ArrayList<>();
for (int i = 0; i < sizeOfList; i++) {
Dog doggy = new Dog(breed, name);
dog.add(doggy);
System.out.println("What's the breed of the dog :");
doggy.breed = s.next();
System.out.println("What's the name of the dog:");
doggy.name = s.next();
}
dog.forEach(System.out::println);
}
public class Liste {
public static void main(String[] args) {
Dog p = new Dog();
p.makeList();
}
}
I expected it to return Name and Breed of the Object (Strings), instead it gave me "liste.Dog@eed1f14"