Java8语言能力-2



 /** * Created by Shusheng Shi on 2017/5/1. */ interface Fly { default void takeOff(){ System.out.println("Fly::takeOff"); } default void turn(){ System.out.println("Fly::turn"); } default void cruise(){ System.out.println("Fly::cruise"); } default void land(){ System.out.println("Fly::land"); } } interface FastFly extends Fly { default void tackOff() { System.out.println("FastFly::takeOff"); } } class Vehicle { public void land() { System.out.println("Vehicel:land"); } } interface Sail { default void cruise() { System.out.println("Sail:cruise"); } } class SeaPlane extends Vehicle implements FastFly { public void cruise() { System.out.println("SeaPlane;cruise"); FastFly.super.cruise(); } } public class Sample { public void use() { SeaPlane seaPlane = new SeaPlane(); seaPlane.tackOff(); seaPlane.turn(); seaPlane.cruise(); seaPlane.land(); } public static void main(String[] args) { new Sample().use(); } } 

输出

  • FastFly::takeOff
  • Fly::turn
  • SeaPlane::cruise
  • Fly::cruise
  • Vehicel:land
  • FastFly::takeOff
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 17:30
点赞 评论 收藏
分享
05-23 19:02
吉林大学 Java
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务