0

whats wrong with it? im trying to loop through a list of objects and print out the content.(name,gender,sound,wings or not)

import java.util.* ; public class Animal { List<String> animalList = new ArrayList<String>() ; String name ; int age ; String gender ; boolean wings ; public Animal(){ } public String get_name(){return name ;} public String get_gender(){return gender;} public void print_sound(){ System.out.println("Usually animals give off some kind of sound.");} public String print_list(){for(String i: animalList){ for(String j : i){<----- I get an error here System.out.println(j); } }} public static void main(String[] args) { } }

21st Sep 2022, 1:52 PM
Lenoname
5 Answers
+ 1
Is it because none of your code is under the main(String[] args)?
21st Sep 2022, 2:04 PM
Ausgrindtube
Ausgrindtube - avatar
0
for(String i :animalList){System.out.println(i.name, i.gender, i.sound, i.wings;} this wouldnt work either
21st Sep 2022, 2:02 PM
Lenoname
0
21st Sep 2022, 2:13 PM
Lenoname
0
Ausgrindtube what part should be?
21st Sep 2022, 2:16 PM
Lenoname
21st Sep 2022, 4:31 PM
Ausgrindtube
Ausgrindtube - avatar