• 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!