《Java面向对象》
第四章 抽象类与接口——实例运用
package 抽象类和接口;
public interface bird {
final int leg=2;
final int egg=3;
void getegg();
}
package 抽象类和接口;
public class dayan implements bird, flyanimal {
public void getegg() {
System.out.println("大雁我下了一窝蛋");
}
@Override
public void fly() {
System.out.println("芜湖起飞");
}
}
```java
package 抽象类和接口;
public interface flyanimal {
public abstract void fly();
}
```java
在这里插入代码片package 抽象类和接口;
public class Ge implements bird,flyanimal{
@Override
public void fly() {
System.out.println("鸽子起飞");
}
@Override
public void getegg() {
System.out.println("叁鸽子蛋");
}
}
package 抽象类和接口;
public interface kunchong {
final int leg=6;
final int lagegg=100;
void getlagegg();
}```
```java
package 抽象类和接口;
public class mayi implements kunchong,flyanimal{
public void fly() {
System.out.println("我是蚂蚁,起飞");
}
@Override
public void getlagegg() {
System.out.println("产一窝卵");
}
}
package 抽象类和接口;
public class mifeng implements kunchong,flyanimal{
public void fly() {
System.out.println("我是蜜蜂,起飞");
}
@Override
public void getlagegg() {
System.out.println("产一窝卵");
}
}
package 抽象类和接口;
public class Test {
public static void main(String[]args) {
Ge g=new Ge();
g.fly();
g.getegg();
dayan d=new dayan();
d.fly();
d.getegg();
mayi m1=new mayi();
m1.fly();
m1.getlagegg();
mifeng m2=new mifeng();
m2.fly();
m2.getlagegg();
}
}