public class Animal { //HomeWork0801
String type;
String voice;
void sound(){
System.out.println(type+"、"+voice);
}
}
public class MyAnimal {
public static void main(String[] args) {
Animal cat=new Animal();
Animal dog=new Animal();
Animal cattle=new Animal();
Animal horse=new Animal();
cat.type="cat";
cat.voice="mew";
dog.type="dog";
dog.voice="bark";
cattle.type="cattle";
cattle.voice="moo";
horse.type="horse";
horse.voice="neigh";
cat.sound();
dog.sound();
horse.sound();
cattle.sound();
}
}
沒有留言:
張貼留言