It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes an enums question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "an enums question" Watch "an enums question" New topic

an enums question

Aakash Goel
Ranch Hand

Joined: May 26, 2008
Posts: 198
This is from ExamLab - paper3

The output is Only A Only B Only C.

How does A [line 1] match the A inside enum? They are completely different!!!

I thought the default case would match.

This [Only A Only B Only C] is the answer I expect if the cases are defined like :

SCJP 5 95%
SCJP FAQ | SCJP Mock Tests | SCJP Tipline | Generics
pete stein

Joined: Feb 23, 2007
Posts: 1561
Per the JLS (14:11): The case labels must be constant expressions, int A is a variable while the enum A is a constant. Also the case label constants must be assignable to the switch expression.
I agree. Here's the link:
subject: an enums question
It's not a secret anymore!