Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-write-java-switch-statement
Question 40 / 297:  What is the result of compiling and running the following code?
public static void main(String[] args) {

int j = 10;

switch (1) {

case 20:

j += 1;

case 40:

j += 2;

default:

j += 3;

case 0:

j += 4;

}

System.out.print(j);

}

A  Compile error, can"t use constant 1 in the switch, must be final variable
B  Compile error, default must be the last statement after all the cases
C  Compile error, must have break statement within each case
D  17
E  13
<< First < Previous Next > Last >>
Explanation:

The compilation will succeed. No match is met, so what in default is executed. Increment j by 3 and since there is no break statement, it will continue to the next statement and increment j by 4 and then exit.

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Rylee Minllic
Start Quiz
Jemekia Weeden
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>