Java Reference
In-Depth Information
LISTING 3.6
continued
cone3 = cone1;
System.out.println ();
System.out.println ("cone3 value: " + cone3);
System.out.println ("cone3 ordinal: " + cone3.ordinal());
System.out.println ("cone3 name: " + cone3.name());
}
}
OUTPUT
cone1 value: rockyRoad
cone1 ordinal: 5
cone1 name: rockyRoad
cone2 value: chocolate
cone2 ordinal: 1
cone2 name: chocolate
cone3 value: rockyRoad
cone3 ordinal: 5
cone3 name: rockyRoad
SELF-REVIEW QUESTIONS
(see answers in Appendix N)
SR 3.29
Write the declaration of an enumerated type that represents movie ratings.
SR 3.30
Suppose that an enumerated type called
CardSuit
has been defined as
follows:
enum
CardSuit {clubs, diamonds, hearts, spades}
What is the output of the following code sequence?
CardSuit card1, card2;
card1 = CardSuit.clubs;
card2 = CardSuit.hearts;
System.out.println (card1);
System.out.println (card2.name());
System.out.println (card1.ordinal());
System.out.println (card2.ordinal());
SR 3.31
Why use an enumerated type such as
CardSuit
defined in the previous
question? Why not just use
String
variables and assign them values
such as “hearts”?
Search WWH ::
Custom Search