【资料图】

1、interface CanFly { void fly(); } class Plane implements CanFly { @Override public void fly() { System.out.println("飞机起飞了!"); } } class Bird implements CanFly { @Override public void fly() { System.out.println("鸟飞了!"); } } public class CanFlyTest { public static void makeFly(CanFly canFly) { canFly.fly(); } public static void main(String[] args) { CanFly plane = new Plane(); CanFly bird = new Bird(); makeFly(plane); makeFly(bird); } }。

本文到此分享完毕,希望对大家有所帮助。


关键词: