接著再main()中建立兩個Animal物件,使分別發出 「狗 旺旺」&「貓 喵嗚」,然後讓兩隻動物叫一聲看看
注意:1~4題是連貫題 要一起看(使用)
public class Animal { //HomeWork0801
String type;
String voice;
void sound(){
System.out.print(type+"、");
System.out.println(voice);
}
void sound2(){
System.out.print(voice);
}
void sound1(String s){
System.out.print(s);
}
public static void main(String[] args) {
Animal cat=new Animal();
Animal dog=new Animal();
cat.type="cat";
cat.voice="mew";
dog.type="dog";
dog.voice="bark";
cat.sound();
dog.sound();
}
}
沒有留言:
張貼留言