• 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

One simple enum question (from HF Java)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all. I have read almost the entire HF Java book. While checking the appendix, I saw something that I can't figure out. This is what they have:



//later down the page



They say the output is "go deep Cassidy!" Why? ifName = Members.PHIL and not Members.BOBBY (or both)
Thanks.
 
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A switch will use the first case it matches, and then every case after that one, unless it encounters a break command.

So this code would jump to PHIL, output "go deep ", then continue on to BOBBY and output "cassidy!".
If you wanted it to print only the line belonging to the case, you would have to put a "break;" after each case's commands.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes exactly Jan
this concept is called "fall threw inside switch" ,that is if any case lable is matched, from that statement onwards all the remaining statements will be executed until some "break" or end of switch.
 
Joe Hernandez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh I see, so that was the use for break way before in the book. Great thanks a lot guys!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic