This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Switch statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Switch statement" Watch "Switch statement" New topic

Switch statement

Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Hello, I was reviewing for the exam, and I was wondering if
anyone could be of assistance in explaining the below statement.
An example would probably help. By the way what is a nested case
label and what do the notes mean when they say don't clash with outer case labels.
The switch can be nested. Nested case labels are independent, don�t clash with outer case labels.
Thank you for the help in advance.

Joined: Jan 31, 2001
Posts: 12
It means the following
int c;
case 0: Do something;
case 1:case 2:
switch (c){
case 0: Do something;
case 1: Do something;
The above switch is nested and inside switch arguement is the same as the one outside and they are independent.
Hope this helps.

Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
it means you can have same case labels in nested switch statement. Example
int i = 1;

Val SCJP <BR>going for SCJD
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Thanks, that clears it up.
I agree. Here's the link:
subject: Switch statement
jQuery in Action, 3rd edition