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
全部评论

相关推荐

11-22 16:49
已编辑
北京邮电大学 Java
美团 质效,测开 n*15.5
点赞 评论 收藏
分享
Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 19:05
面试官_我太想进步了:混学生会的,难怪简历这么水
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务