Specifications

Sun Services
Java™ Programming Language
Module 7, slide 23 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Advanced Enumerated Types
Enumerated types can have attributes and methods:
0
1 package cards.domain;
2
3 public enum Suit {
4 SPADES (“Spades”),
5 HEARTS (“Hearts”),
6 CLUBS (“Clubs”),
7 DIAMONDS (“Diamonds”);
8
9 private final String name;
10
11 private Suit(String name) {
12 this.name = name;
13 }
14
15 public String getName() {
16 return name;
17 }
18 }