Ramya Subraamanian wrote:But does this make the statement 'C' true?
That's easy to verify with a quick and simple code snippet
If you try to compile this code snippet, you'll get a compiler error on
line1: "
continue outside of loop" (or something similar). So a
continue statement can
not be used inside a
switch statement.
And you could indeed use a
continue statement in a
switch statement if this
switch statement is used inside a loop.
This code snippet compiles successfully, but this does
not make answer C true! If that would have been the case then the correct answer would have been B because then you could use a
continue statement in an
if statement too
But when using the
continue statement in an
if statement without a loop, you'll get the same compiler error as with the
switch statement
Please note that it does not make any difference if you have a labeled or unlabeled
continue statement,
Hope it helps!
Kind regards,
Roel
PS. It was
reported a few years ago as an errata for the OCA
Java SE 7 study guide, but it seems it was not processed by the authors.