标签:
感觉越来越强烈,
我的心在跳~~~,我的宝剑在嘟~~
Flyer.java
package cc.openhome; public interface Flyer{ public abstract void fly(); }
Swimmer.java
package cc.openhome; public interface Swimmer{ public abstract void swim(); }
Fish.java
package cc.openhome; public abstract class Fish implements Swimmer { protected String name; public Fish(String name){ this.name = name; } public String getName() { return name; } @Override public abstract void swim(); }
FlyingFish.java
package cc.openhome; public class FlyingFish extends Fish implements Flyer { public FlyingFish(String name){ super(name); } @Override public void swim(){ System.out.println("FlyingFish swim"); } @Override public void fly(){ System.out.println("FlyingFish fly"); } }
SeaPlane.java
package cc.openhome; public class Seaplane implements Swimmer, Flyer { private String name; public Seaplane(String name){ this.name = name; } @Override public void fly() { System.out.printf("Seaplane %s is fly", name); } @Override public void swim(){ System.out.printf("Seaplane %s is swim", name); } }
Ocean.java
package cc.openhome; public class Ocean { public static void main(String[] args){ doSwim(new Seaplane("AirFoce Zero")); doSwim(new FlyingFish("Flying Ping")); } static void doSwim(Swimmer swimmer){ swimmer.swim(); } }
标签:
原文地址:http://www.cnblogs.com/aguncn/p/5424400.html