This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an enums question

 
Aakash Goel
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :



 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic