Originally posted by Kamil Dada:
Take a look at this question:
Q57.What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q57
2 {
3 public static void main(String arg[])
4 {
5 int j=0;
6 switch(1)
7 {
8 case 2: j+=1;
9 case 4: j+=2;
10 default: j+=3;
11 case 0: j+=4;
12 }
13 System.out.println(j);
13 }
14 }
Answer = Program compiles correctly and print 7 when executed as we have not used break
Can someone please explain this to me, and also why is there a (1) in the switch statement and what does it represent?
Thank You
Kamil
Gagan (/^_^\) SCJP2 SCWCD IBM486 <br />Die-hard JavaMonk -- little Java a day, keeps you going.<br /><a href="http://www.objectfirst.com/blog" target="_blank" rel="nofollow">My Blog</a>
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |