Quote (ferf @ Apr 23 2016 10:45pm)
I changed to boolean for check method... (not sure if that's what i was supposed to do, but it seems to have fixed the error)
but i still get this error:
Code
Animal2.java:12: error: missing return statement
}
^
here is newest code:
Code
class Animal {
boolean omnivore;
boolean carnivore;
boolean herbavore;
boolean check() {
if(omnivore == true) System.out.println("omnivore");
if(carnivore == true) System.out.println("carnivore");
if(herbavore == true) System.out.println("herbavore");
}
}
class Animal2 {
public static void main(String args[]) {
Animal dog = new Animal();
Animal tiger = new Animal();
Animal skunk = new Animal();
dog.omnivore = true;
tiger.carnivore = true;
skunk.herbavore = true;
System.out.println("Dog is a " + dog.check());
System.out.println("tiger is a " + tiger.check());
System.out.println("Skunk is a " + skunk.check());
}
}
two things.
1) why did you choose boolean? do you really want a boolean here?
Quote
System.out.println("Dog is a " + dog.check());
2) you're saying the check method returns a boolean. where are you returning it? i dont see a return statement.
Code
boolean check() {
if(omnivore == true) System.out.println("omnivore");
if(carnivore == true) System.out.println("carnivore");
if(herbavore == true) System.out.println("herbavore");
}
hence the error "missing return statement"