?????????????????
???????????? ???????[ 2013/8/7 11:04:16 ] ????????
????1.??????
???????仯????????????????????????????????????????????????????????仯???????????
????2.???????
???????漰????????????????????????ü?У???????????????????????????????????????????????????????????????и÷?????????????Щ???t???÷????????????????????????????????????
publicabstractclassDuck{
//???е????????????????????????д??????????
publicvoidquack(){
System.out.println("Quack");
}
publicvoidswim(){
System.out.println("Allducksfloat??evendecoys.");
}
//????????????????????????????и÷???????????????????????ɡ?
publicabstractvoiddisplay();
}
publicclassMallardDuckextendsDuck{
//????????????
publicvoiddisplay(){
System.out.println("Greenhead.");
}
}
publicclassRedHeadDuckextendsDuck{
//???????????
publicvoiddisplay(){
System.out.println("Redhead.");
}
}
publicclassRubberDuckextendsDuck{
//????????????У???????д???????д???
publicvoidquack(){
System.out.println("Squeak");
}
//???????????
publicvoiddisplay(){
System.out.println("Yellowhead.");
}
}
??????????????????÷???á??????????????Duck.java?м???fly()?????????????????????о?????÷????????????????????????????????????????????????????????????????д?÷????????÷????????????????????????????????????????????
???????????????????????????????????
????a.?????????????????;
????b.??????????????????
????c.??????????????????????????????????
??????????????????????????????????y??????????????е??????????????????Duck????????????????Щ???????????????????
publicabstractclassDuck{
//???仯?????fly()???quake()??Duck???з??????????γ?????????????????????????
publicvoidswim(){
System.out.println("Allducksfloat??evendecoys.");
}
publicabstractvoiddisplay();
}
//?仯??fly()????????γ????
publicinterfaceFlyBehavior{
voidfly();
}
//?仯??quack()????????γ????
publicinterfaceQuackBehavior{
voidquack();
}
//??????????У??????????FlyBehavior??QuackBehavior
publicclassMallardDuckextendsDuckimplementsFlyBehavior??QuackBehavior{
publicvoiddisplay(){
System.out.println("Greenhead.");
}
publicvoidfly(){
System.out.println("Fly.");
}
publicvoidquack(){
System.out.println("Quack.");
}
}
//????????????У???????????FlyBehavior??QuackBehavior
publicclassRedHeadDuckextendsDuckimplementsFlyBehavior??QuackBehavior{
publicvoiddisplay(){
System.out.println("Redhead.");
}
publicvoidfly(){
System.out.println("Fly.");
}
publicvoidquack(){
System.out.println("Quack.");
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11