class Animal {
boolean omnivore;
boolean carnivore;
boolean herbavore;
void check() {
if(omnivore == true) System.out.println("is an omnivore");
if(carnivore == true) System.out.println("is an carnivore");
if(herbavore == true) System.out.println("is an 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());
}
}
Errors:
Code
C:\Users\ferfy\Desktop>javac Animal2.java
Animal2.java:28: error: 'void' type not allowed here
System.out.println("Dog is a " + dog.check());
^
Animal2.java:29: error: 'void' type not allowed here
System.out.println("tiger is a " + tiger.check());
^
Animal2.java:30: error: 'void' type not allowed here
System.out.println("Skunk is a " + skunk.check());
Not sure what i'm doing wrong
This post has been edited by ferfykins: 23 April 2016 - 07:37 PM

New Topic/Question
Reply


MultiQuote



|