Advertisement
AkramAbd

8.10 Declaring an enum type with constructor and explicit in

Mar 6th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // Fig. 8.10: Book.java
  2. // Declaring an enum type with constructor and explicit instance fields
  3. // and accessors for these fields
  4.  
  5. public enum Book
  6. {
  7. // declare constants of enum type
  8. JHTP( "Java How to Program", "2012" ),
  9. CHTP( "C How to Program", "2007" ),
  10. IW3HTP( "Internet & World Wide Web How to Program", "2008" ),
  11. CPPHTP( "C++ How to Program", "2012" ),
  12. VBHTP( "Visual Basic 2010 How to Program", "2011" ),
  13. CSHARPHTP( "Visual C# 2010 How to Program", "2011" );
  14.  
  15. // instance fields
  16. private final String title; // book title
  17. private final String copyrightYear; // copyright year
  18.  
  19. // enum constructor
  20. Book( String bookTitle, String year )
  21. {
  22. title = bookTitle;
  23. copyrightYear = year;
  24. } // end enum Book constructor
  25.  
  26. // accessor for field title
  27. public String getTitle()
  28. {
  29. return title;
  30. } // end method getTitle
  31.  
  32. // accessor for field copyrightYear
  33. public String getCopyrightYear()
  34. {
  35. return copyrightYear;
  36. } // end method getCopyrightYear
  37. } // end enum Book
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement