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