bird and cow sound
Submit solution
Points:
60
Time limit:
1.0s
Memory limit:
256M
Authors:
Problem type
Allowed languages
Java 19, Java 8
題目說明
請透過以下提示,覆寫speak()
分別讓他們輸出鳥叫聲tweak!
和牛叫聲moo!
在class bird
和class cow
中
class animal {
void speak() {
System.out.println("The animal makes a sound.");
}
}
class bird extends animal {
@Override
/*
輸入在此
*/
}
class cow extends animal {
@Override
/*
輸入在此
*/
}
public class t05311 {
public static void main(String[] args) {
animal genericanimal = new animal();
bird mybird = new bird();
cow mycow = new cow();
animal animals[] = {genericanimal, mybird, mycow};
for (animal animal : animals) {
animal.speak();
}
}
}
輸入
這題不用輸入
輸出
分別輸出speak()
測試資料輸入
這題不用輸入
測試資料輸出
The animal makes a sound.
tweak!
moo!
//若直接print結果出來將不予計分!
Comments
題解
參考課堂範例A290