1. public class Stock1 {
    2. public void Buy(){
    3. System.out.println("股票一买入");
    4. }
    5. public void Sell(){
    6. System.out.println("股票一卖出");
    7. }
    8. }
    9. public class Stock2 {
    10. public void Buy(){
    11. System.out.println("股票二买入");
    12. }
    13. public void Sell(){
    14. System.out.println("股票二卖出");
    15. }
    16. }
    17. public class Stock3 {
    18. public void Buy(){
    19. System.out.println("股票三买入");
    20. }
    21. public void Sell(){
    22. System.out.println("股票三卖出");
    23. }
    24. }
    25. public class Fund {
    26. Stock1 stock1;
    27. Stock2 stock2;
    28. Stock3 stock3;
    29. public Fund(){
    30. stock1 = new Stock1();
    31. stock2 = new Stock2();
    32. stock3 = new Stock3();
    33. }
    34. public void Buy(){
    35. stock1.Buy();
    36. stock2.Buy();
    37. stock3.Buy();
    38. }
    39. public void Sell(){
    40. stock1.Sell();
    41. stock2.Sell();
    42. stock3.Sell();
    43. }
    44. }
    45. public class Test {
    46. public static void main(String[] args) {
    47. Fund fund = new Fund();
    48. fund.Buy();
    49. fund.Sell();
    50. }
    51. }