• Post Reply Bookmark Topic Watch Topic
  • New Topic

Chapter 2, pg 75-76, switch statements (Java OCA 8 Programmer I Study Guide, Sybex)

 
Tami Wakana
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For switch statements, I understand enum constants are allowed




I understand why they all don't compile. I'm wondering what an enum constant would look like (the last one doesn't compile because it is an enum value, not a constant)

[edited to fixed code tags]
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tami Wakana wrote:I'm wondering what an enum constant would look like (the last one doesn't compile because it is an enum value, not a constant)

Last one doesn't compile because cannot convert from enum DayOfWeek to String i.e. firstName means expecting String found enum
Here  java.time.DayOfWeek.SUNDAY is enum constant. They used fully qualified name of enum constant SUNDAY.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36014
423
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tami,
Enums aren't in the OCA. You'll learn this for the OCP. But here's a preview:

This is an enum


And this is a switch statement that uses the enum
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!