package b; public interface CanFly { public void fly(); }
package b; public class FeiJi implements CanFly { @Override public void fly() { System.out.println("飞机 化工能源飞行"); } }
package b; public class Niao implements CanFly { @Override public void fly() { System.out.println("鸟 生物能源飞行"); } }
package b; public class TestFly { static void makeFly(CanFly a) { System.out.println("准备起飞!"); } public static void main(String[] args) { FeiJi jixie=new FeiJi(); jixie.fly(); CanFly a=jixie; TestFly.makeFly(a); Niao shengwu=new Niao(); shengwu.fly(); CanFly b=shengwu; TestFly.makeFly(b); } }