Salve a tutti spero con questo post di non infrangere nessuna parte del regolamento![]()
Avrei un problema di interpretazione con questo file che non inserirò nel formato code per far rispettare l'ordine:
enum CoffeeSize {
// 8, 10 & 16 are passed to the constructor
BIG(8), HUGE(10), OVERWHELMING(16);
CoffeeSize(int ounces) { // constructor
this.ounces = ounces;
}
private int ounces; // an instance variable
public int getOunces() {
return ounces;
}
}
class Coffee {
CoffeeSize size; // each instance of Coffee has an enum
public static void main(String[] args) {
Coffee drink1 = new Coffee();
drink1.size = CoffeeSize.BIG;
Coffee drink2 = new Coffee();
drink2.size = CoffeeSize.OVERWHELMING;
System.out.println(drink1.size.getOunces()); // prints 8
for(CoffeeSize cs: CoffeeSize.values())
System.out.println(cs + " " + cs.getOunces());
}
}
Cio che non capisco è class Coffee { CoffeeSize size; ... che dichiarazione sarebbe coffeSize size;? E un'altra cosa: quando viene creato un new Coffee come puo venire creato se Coffee non è stato dichiarato in precedenza? Grazie mille

Rispondi quotando

