public interface Eat {
public default void eatting(){
System.out.println("我可以吃饭");
}
}
interface Walk{
public abstract void walking();
}
interface Speak{
public default void speaking(){
System.out.println("我可以说");
}
}
class Animal extends Creature implements Eat,Walk{
@Override
public void walking() {
System.out.println("animal可以爬行。。。。。");
}
@Override
public void eatting() {
System.out.println("animal过着茹毛饮血的生活");
}
@Override
public void speaking() {
System.out.println("我可以咆哮");
}
}
class People extends Creature implements Walk,Eat{
@Override
public void eatting() {
System.out.println("人类可以吃热饭");
}
@Override
public void walking() {
System.out.println("人类会步行");
}
}
class Creature implements Speak{
int age;
//如果接口中的方法是抽象的,那就必须要在实现类中重写接口中的方法
//speak()方法,不是抽象的,所以可以不重写
}
class 测试{
public static void main(String[] args) {
Animal an=new Animal();
an.eatting();
an.walking();
People p=new People();
p.eatting();
p.walking();
Creature c1=new People();
c1.speaking();
Animal a=new Animal();
Creature c=a;
a.speaking();
}
}
运行结果: