运java语言1、按以下要求编写程序 (1)编写 Animal接口,接口中声明run()方法 (2)编写 Bird 类和 Fish 类实现 Aniaml 接口 (3)编马 Bird 类和 Fish 类的测试程序,井调用其中的run( 方法
时间: 2024-03-20 14:40:49 浏览: 130
用Java写的一些程序
可以参考以下代码:
Animal.java
```
public interface Animal {
void run();
}
```
Bird.java
```
public class Bird implements Animal {
@Override
public void run() {
System.out.println("Bird is flying...");
}
}
```
Fish.java
```
public class Fish implements Animal {
@Override
public void run() {
System.out.println("Fish is swimming...");
}
}
```
测试程序
```
public class AnimalTest {
public static void main(String[] args) {
Animal bird = new Bird();
bird.run();
Animal fish = new Fish();
fish.run();
}
}
```
输出结果:
```
Bird is flying...
Fish is swimming...
```
阅读全文