SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Regards
vinod SCJP 6.0
I compiled your code and noticed that if you change the order of the case statements ie put the default case at last and then comment out the return statement of the default case it is not showing any problem .
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Regards
vinod SCJP 6.0
Regards
vinod SCJP 6.0
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Regards
vinod SCJP 6.0
SCJP 6.0
SCJP 5
Originally posted by ARIJIT DARIPA:
class SwitchTries{
public static void main(String[] args){
int i=10;
switch(i){
case 15:
if(false) break;
return;
case 10:
return;
default:
return;
case 30:
return;
}
System.out.println("Can be Reached");
}
}
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6.0
Originally posted by Ankit Garg:
int iVal;
if(true)
{
iVal = 10;//(1)
}
else
{
System.out.println(15);
}
Originally posted by Quirino Gervacio:
if(true){}
else{}
may be the compiler here assumes that you know what you are doing even though us, humans can tell that the else will never get executed :-)
SCJP 5
Originally posted by ARIJIT DARIPA:
Had the compiler spat error on the else block at line 1, it would have to say there is a compilation error at line 3.
Oh! imagine, we have to know the values of static final variables before comparing them.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Regards
vinod SCJP 6.0
Originally posted by Ankit Garg:
I didn't understand what you said. I also modified your code a bit...
SCJP 5
Cleared SCJP 1.5 | Cleared SCWCD 5.0
SCDJWS 6 in progress.....
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |