Java Reference
In-Depth Information
constants the enum represents. For example, we can rewrite our suit
example using an enum:
enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
Each enum constant is a static field that refers to the object for that
valuesuch as Suit.HEARTS . By representing each named constant as an
object rather than just an integer value, you improve the type-safety
and so the robustness, of your program. Enums are covered in detail in
Chapter 6 .
Exercise 1.5 : Change the HelloWorld application to use a named string
constant as the string to print. (A string constant can be initialized with
a string literal.)
Exercise 1.6 : Change your program from Exercise 1.3 to use a named
string constant for the title.
 
Search WWH ::




Custom Search