aspose file tools*
The moose likes Mock Exam Errata and the fly likes Which the answer is ture? and  why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Which the answer is ture? and  why? " Watch "Which the answer is ture? and  why? " New topic
Author

Which the answer is ture? and why?

PANDORA
Greenhorn

Joined: Jul 23, 2001
Posts: 5
int i = 100;
switch (i) {
case 100 :
System.out.println(i);
case 200 :
System.out.println(i);
case 300 :
System.out.println(i);
}
A) Nothing is printed


B) Compile time error


C) The values 100,100,100 printed


D) Only 100 is printed
Thanks~~!

wellcome to guobao.net<BR>[img]http://www.guobao.net/image/GBLOGO.jpg[/img] <BR>[url]http://www.guobao.net[url]
Dave Soto
Ranch Hand

Joined: Sep 15, 2001
Posts: 55
C) The values 100,100,100 printed
This is because there are no break statements. Without the break statements, the case 100: is executed, and then 100 is printed. Then, the case 200: is basically ignored, and 100 is printed again. Finally, the case 300: is also ignored, and so 100 is printed again.
Hope that helps!
PANDORA
Greenhorn

Joined: Jul 23, 2001
Posts: 5
Thanks a lot
But why the case2 will be ignored?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Which the answer is ture? and why?