本文共 1287 字,大约阅读时间需要 4 分钟。
呵呵,除了输出语句,其它几乎完全一样。
看来都是类C。流着同样的血液。
1 class Stock 2 { 3 public void Sell() 4 { 5 System.out.println("Sell Stock"); 6 } 7 public void Buy() 8 { 9 System.out.println("Buy Stock");10 }11 }12 13 class NationDebt14 {15 public void Sell()16 {17 System.out.println("Sell NationDebt");18 }19 public void Buy()20 {21 System.out.println("Buy NationDebt");22 }23 }24 25 class Realty26 {27 public void Sell()28 {29 System.out.println("Sell Realty");30 }31 public void Buy()32 {33 System.out.println("Buy Realty");34 }35 }36 37 class Fund38 {39 Stock st;40 NationDebt nd;41 Realty re;42 43 public Fund()44 {45 st = new Stock();46 nd = new NationDebt();47 re = new Realty();48 }49 50 public void BuyFund()51 {52 st.Buy();53 nd.Buy();54 re.Buy();55 }56 public void SellFund()57 {58 st.Sell();59 nd.Sell();60 re.Sell();61 }62 }63 class ArrayApp64 {65 66 public static void main(String[] args)67 {68 Fund fd = new Fund();69 fd.BuyFund();70 System.out.println("========");71 fd.SellFund();72 73 } 74 }
转载地址:http://jpqko.baihongyu.com/