摘要:[Java代碼](1)FlyBehavior{publicvoidfly();};(2)QuackBehavior{publicvoidquack();};classFlyWithWingsimplementsFlyBehavior{publicvoidfly(){System.out.println("使用翅膀飛行!");}};classFlyNoWayimplementsFlyBehavior{publicvoidfly(){System.out.printl
[Java代碼]
(1) FlyBehavior {
public void fly();
};
(2) QuackBehavior {
public void quack();
};
class FlyWithWings implements FlyBehavior{
public void fly(){ System.out.println("使用翅膀飛行 !"); }
};
class FlyNoWay implements FlyBehavior{
public void fly(){ System.out.println("不能飛行 !" ); }
};
class Quack implements QuackBehavior{
public void quack(){ System.out.println("發(fā)出\'嘎嘎\'聲 !" ); }
};
class Squeak implements QuackBehavior{
public void quack(){ System.out.println("發(fā)出空氣與橡皮摩擦聲 !"); }
};
class QuackNoWay implements QuackBehavior{
public void quack (){ System.out.println("不能發(fā)聲 !" ); }
};
abstract class Duck {
protected FlyBehavior (3);
protected QuackBehavior (4);
public void fly(){ (5); }
public void quack() { (6) ; };
public (7) void display();
};
class RubberDuck extends Duck {
public RubberDuck(){
flyBehavior = new (8) ;
quackBehavior = new (9) ;
}
public void display(){ /* 此處省略顯示橡皮鴨的代碼 */ }
};
//其它代碼省略
軟考備考資料免費(fèi)領(lǐng)取
去領(lǐng)取
共收錄117.93萬道題
已有25.02萬小伙伴參與做題