What is the result?

Given the code fragment:

What is the result?
A. Compilation fails.
B. 0 Found
C. 1 Found
D. 3 Found

Download Printable PDF. VALID exam to help you PASS.

9 thoughts on “What is the result?

  1. this is very bad java syntax, even if you ignore all the error and try to make sense of this coding, the code will still give an exception because of the continue statement which causes the post-incrementation line to be unreachable.

  2. A:

    # javac Test29.java
    Test29.java:9: error: unreachable statement
    count++;
    ^
    1 error
    —————————–
    Based on provided error, if put count before “continue”, compilation will be successful with following result:

    # javac Test29.java
    # java Test29
    3

  3. Answer A:

    After the if condition is true, “continue” will always be executed, making the count++ unreachable.
    Also, there is a colon instead of semicolon after “continue”. Not sure on whether this is a typo in the question or this is intentionally added. If so, this also makes Answer A the correct answer.

  4. Well, the line with ” continue:” contain a unexpected token. Here the ” : ” is not allowed. If one correct it to ” continue;”
    you will get the error mention abow. ‘count++ is unreachable’ . But still error A .

Leave a Reply

Your email address will not be published.