O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Review Questions

5.5 What will be the result of attempting to compile and run the following code?
class MyClass {
    public static void main(String[] args) {
        boolean b = false;
        int i = 1;
        do {
            i++;
            b = ! b;
        } while (b);
        System.out.println(i);
    }
}

Select the one correct answer.

  1. The code will fail to compile, since b is an invalid conditional expression for the do-while statement.

  2. The code will fail to compile, since the assignment b = ! b is not allowed.

  3. The code will compile without error and will print 1 when run.

  4. The code will compile without error and will print 2 when run.

  5. The code will compile without error and will print 3 when run.

5.6 What will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required