File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch statement question

 
sarim raza
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic