第一个是枚举类
enum coffeeSize{
BIG(8), HUGE(10), OVERWHELMING(16);
private int ounces;
coffeeSize(int ounces ){
this.ounces = ounces;
}
public int getOunces(){
return ounces;
}
}
这是类 CoffeeTest1 和 main
public class CoffeeTest1 {
coffeeSize size;
public static void main (String args[]) {
CoffeeTest1 drink1 = new CoffeeTest1();
drink1.size = coffeeSize.BIG;
System.out.println(" " + drink1.size.getOunces());
}
}
下面是输出
8
我的问题:我不明白如何drink1.size.getounces()
输出 8。我没有给出构造函数coffeeSize(8)
对象(例如:)coffeeSize somex = new coffeeSize(BIG)
。我想知道这背后简单微妙的逻辑。有人可以帮我理解吗?