File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch statement question 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 » Programmer Certification (SCJP/OCPJP)
Bookmark "switch statement question" Watch "switch statement question" New topic
Author

switch statement question

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
I am confused about the answer choice B for this question, which is false. Can someone explain why , please, thanks!
----------------------------------------------------------------
1. which of the following are true for a switch statement?
A]all switch statements must have a default label
B]there must be atleast one label for each code segment
C]keyword continue can never occur
D]no case label may follow a default label
E]char literal can be used
Sapna Mathur
Greenhorn

Joined: Nov 06, 2000
Posts: 8
A]all switch statements must have a default label -> False
B]there must be atleast one label for each code segment -> False
C]keyword continue can never occur -> True
D]no case label may follow a default label -> False
E]char literal can be used -> True
sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
thanks sapna,can you please explain why B is false
and also are you sure that there cant be a continue in a switch statement.
thanks!
atin sehgal
Ranch Hand

Joined: Nov 12, 2000
Posts: 32
Hi!
Sarim u have asked why the answer is false for this question.
well--->
B]there must be atleast one label for each code segment

The structure for a switch case statement is:
Switch(value)
case 1:{-------}
case 2:{-----}
default{----}
Now if there were to be no case statement present for each code statement enclosed in brackets (-----) , then the switch statement cannot execute unless default is present.

cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: switch statement question