Hi,
think of ENUM as a class having its constants declared in the following way (your example enum Drinks):
public static final Drinks COFFEE;
public static final Drinks TEA;
public static final Drinks JUICE;
public static final Drinks LASSI;
All four constructors are invoked because above members are initialized in a static initialization block (meaning that they are initialized when the class is first loaded):
static
{
COFFEE = new Drinks("COFFEE", 0, "hot", 10D);
TEA = new Drinks("TEA", 1, "hot", 5D);
JUICE = new Drinks("JUICE", 2, "cold", 20D);
LASSI = new Drinks("LASSI", 3, 8D);
$VALUES = (new Drinks[] {
COFFEE, TEA, JUICE, LASSI
});
}
By the way,
you should have the following in the main method:
Drinks dr = Drinks.LASSI;
Otherwise you get compiler eror.
Moreover, you cannot invoke an ENUM constructor directly, it is invoked automatically, as I presented above.
Hope this helps.
[ July 17, 2008: Message edited by: Jarek Jankowski ]