打字猴:1.700477594e+09
1700477594
1700477595 public void cry(){
1700477596
1700477597 System.out.println(“叫声是克噜——克噜——克噜”);
1700477598
1700477599 }
1700477600
1700477601 //白天鹅的外形
1700477602
1700477603 public void desAppaearance(){
1700477604
1700477605 System.out.println(“外形是纯白色,惹人喜爱”);
1700477606
1700477607 }
1700477608
1700477609 //天鹅是能够飞行的
1700477610
1700477611 public void fly(){
1700477612
1700477613 System.out.println(“能够飞行”);
1700477614
1700477615 }
1700477616
1700477617 }
1700477618
1700477619 但是,鸭妈妈却不认为自己这个另类的孩子是白天鹅,它从自己的观点出发,认为她很丑陋,有碍自己的脸面,于是驱赶她——鸭妈妈把这只小天鹅误认为一只鸭。我们来看实现,如代码清单31-16所示。
1700477620
1700477621 代码清单31-16 把白天鹅当做小鸭子看待
1700477622
1700477623 public class UglyDuckling extends WhiteSwan implements Duck{
1700477624
1700477625 //丑小鸭的叫声
1700477626
1700477627 public void cry(){
1700477628
1700477629 super.cry();
1700477630
1700477631 }
1700477632
1700477633 //丑小鸭的外形
1700477634
1700477635 public void desAppearance(){
1700477636
1700477637 super.desAppaearance();
1700477638
1700477639 }
1700477640
1700477641 //丑小鸭的其他行为
1700477642
1700477643 public void desBehavior(){
[ 上一页 ]  [ :1.700477594e+09 ]  [ 下一页 ]