| Author |
switch stmt
|
anushree ari
Ranch Hand
Joined: Sep 30, 2002
Posts: 98
|
|
class switch1{ public static void main(String args[]) { char ch='c'; switch(ch) { default: case 'a':System.out.println("a");break; case 'b':System.out.println("b");break; } } } it prints "a" how? anybody ans me thx
|
anushree
|
 |
shweta mathur
Ranch Hand
Joined: Sep 23, 2002
Posts: 109
|
|
Anushree, That is becoz of the position of default statement.There is no break statement after default, so the next case is considered & "a" is printed. Only when it finds break statement, the switch statement is left. Change your program to the following and nothing will be printed. Remember : Execution of the BREAK statement only transfers control out of the switch statement, else execution of the next label continues.
|
--Shweta<br />SCJP 1.4 <br />SCWCD
|
 |
 |
|
|
subject: switch stmt
|
|
|