package c; public interface Icanfly { void fei(); }
package c; public class feiji implements Icanfly { //飞机 @Override public void fei() { System.out.println("我是飞机,我能飞"); } }
package c; public class niao implements Icanfly { @Override public void fei() { System.out.println("我是鸟,我能飞"); } }
package c; public class ceshifei { public static void main(String[] args) { feiji f1 = new feiji(); //f1.fei(); niao n1 = new niao (); //n1 .fei(); //让能飞的事物飞起来 makefly(f1); makefly(n1); } //让会飞的事物飞起来 public static void makefly(Icanfly cf) { cf.fei(); } }
时间: 2024-12-19 16:18:33