小编use*_*682的帖子

我可以在接口中声明正常功能吗?

我在oracle网站上学习过Java.在那,我看到了这样的例子

public class Horse {
   public String identifyMyself() {
      return "I am a horse.";
   }
}
public interface Flyer {
   default public String identifyMyself() {
       return "I am able to fly.";
   }
}
public interface Mythical {
   default public String identifyMyself() {
       return "I am a mythical creature.";
   }
}
public class Pegasus extends Horse implements Flyer, Mythical {
   public static void main(String... args) {
       Pegasus myApp = new Pegasus();
       System.out.println(myApp.identifyMyself());
   }
}
Run Code Online (Sandbox Code Playgroud)

我能写这样的界面吗?我希望我只能在界面中编写抽象函数.那么为什么在oracle网站上他们给出了这样的例子呢?

java interface java-8

2
推荐指数
1
解决办法
180
查看次数

标签 统计

interface ×1

java ×1

java-8 ×1