文件名称:duck的java程序
文件大小:45KB
文件格式:DOC
更新时间:2014-10-12 14:11:41
java duck
//duck.java public abstract class Duck { FlyBehavior flyBehavior; QuackBehavior quackBehavior; public Duck(){ } public abstract void display(); public void performFly() { flyBehavior.fly(); } public void performQuack() { quackBehavior.quack(); } public void swim() { System.out.println("All ducks float,even decoys!"); } public void setFlyBehavior(FlyBehavior fb){ flyBehavior = fb; } public void setQuackBehavior(QuackBehavior qb){ quackBehavior = qb; } }