Specifications
Sun Services
Java™ Programming Language
Module 7, slide 22 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
The New Enumerated Type
Enumerated types are type-safe:
0
1 package cards.tests;
2
3 import cards.domain.PlayingCard;
4 import cards.domain.Suit;
5
6 public class TestPlayingCard {
7 public static void main(String[] args) {
8
9 PlayingCard card1
10 = new PlayingCard(Suit.SPADES, 2);
11 System.out.println(“card1 is the “ + card1.getRank()
12 + “ of “ + card1.getSuitName());
13
14 // PlayingCard card2 = new PlayingCard(47, 2);
15 // This will not compile.
16 }
17 }










