函数题:Birds
1. Design an abstract class named Bird to represent a bird. The class contains an void sing() method to print "This bird sings".
2. Design an interface named Flyable to represent anything can fly and contains an void fly() method.
3. Design a concrete class named Chicken as subclass of Bird and override the sing() method to print "Chicken sings"
4. Design a concrete class named Superman as subclass of Flyable and override the fly() method to print "Superman flies"
5. Design a concrete class named Parrot as subclass of Flyable and Bird and override the methods fly() and sing() to print "Parrot flies" and "Parrot sings" separately.
### 裁判测试程序样例:
c++
import java.util.Scanner;
class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i = in.nextInt();
Flyable[] f = { new Parrot(), new Superman() };
for (Flyable k : f) {
k.fly();
}
System.out.println(i);
Bird[] a = { new Parrot(), new Chicken() };
for ( Bird b : a ) {
b.sing();
}
in.close();
}
}
/* 请在这里填写答案 */
### 输入样例:
in
123
### 输出样例:
out
Parrot flies
Superman flies
123
Parrot sings
Chicken sings
答案:若无答案欢迎评论
2. Design an interface named Flyable to represent anything can fly and contains an void fly() method.
3. Design a concrete class named Chicken as subclass of Bird and override the sing() method to print "Chicken sings"
4. Design a concrete class named Superman as subclass of Flyable and override the fly() method to print "Superman flies"
5. Design a concrete class named Parrot as subclass of Flyable and Bird and override the methods fly() and sing() to print "Parrot flies" and "Parrot sings" separately.
### 裁判测试程序样例:
c++
import java.util.Scanner;
class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i = in.nextInt();
Flyable[] f = { new Parrot(), new Superman() };
for (Flyable k : f) {
k.fly();
}
System.out.println(i);
Bird[] a = { new Parrot(), new Chicken() };
for ( Bird b : a ) {
b.sing();
}
in.close();
}
}
/* 请在这里填写答案 */
### 输入样例:
in
123
### 输出样例:
out
Parrot flies
Superman flies
123
Parrot sings
Chicken sings
答案:若无答案欢迎评论