Пример #1
0
  public static Container createCup() {

    Cup cup = new Cup(1, Size.LARGE);
    Scoop scoop1 = new Scoop(Flavor.VANILLA, 3.0, Arrays.asList(Topping.NUTS));
    Scoop scoop2 = new Scoop(Flavor.CHOCOLATE, 2.0, Arrays.asList(Topping.EXTRACHOCOLATE));
    Scoop scoop3 =
        new Scoop(Flavor.CHOCOLATE, 1.0, Arrays.asList(Topping.NUTS, Topping.STRAWBERRYJEERRY));

    cup.setBottomScoop(scoop1);
    scoop1.addScoop(scoop2);
    scoop2.addScoop(scoop3);

    return cup;
  }
Пример #2
0
 /** @param args */
 public static void main(String[] args) {
   System.out.println("Inside main()");
   Cups.c1.f(99);
   // 因为在初始化过程中创建了两个Cup对象
   System.out.println("当前创建Cup对象数: " + Cup.getCounter());
   // 输出为:
   // Inside main()
   // Cup(1)
   // Cup(2)
   // f(99)
   // 当前创建Cup对象数: 2
 }