- 接口是可以多继承的
- 接口不能被实例化
- 格式是:【访问权限】 interface 接口名 {
公开静态常量列表;
(public static final)int a =10;
公共抽象方法列表;
(public abstract)void t1();
(JDK1.8后有默认方法)
default void t4(){
方法体
}
}
public class TestBird {
public static void main(String[] args) {
Bird bird1 = new Bird();
bird1.eat();
bird1.fly();
IFly bird2 = new Bird();
bird2.fly();
}
}
interface IFly {
void fly();
}
interface IEat {
void eat();
}
class Bird implements IFly,IEat{
@Override
public void fly() {
System.out.println("笨鸟在飞");
}
@Override
public void eat() {
System.out.println("笨鸟在吃虫子");
}
}
