• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

behavior of switch statement with enums

 
Greenhorn
Posts: 13
Mac Mac OS X Mac PPC
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it prints "sunday"

why not

"default
final float
sunday"
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jobless jack wrote:
it prints "sunday"

why not

"default
final float
sunday"


Time for you to get to know the Java Language Specification. See section 14.11.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The position of the default statement doesn't matter - it's still only executed if none of the case conditions match (as your example shows).

One reason why it's a really bad idea to put it anywhere other than at the end of the switch statement.

 
Jack McLaren
Greenhorn
Posts: 13
Mac Mac OS X Mac PPC
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:The position of the default statement doesn't matter - it's still only executed if none of the case conditions match (as your example shows).

One reason why it's a really bad idea to put it anywhere other than at the end of the switch statement.



thank you

now i understand, how this program works.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic