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

10.28 What will be the result of attempting to compile and run the following program?
public class MyClass {
    public static void main(String[] args) {
        String s = "hello";
        StringBuffer sb = new StringBuffer(s);
        sb.reverse();
        if (s == sb) System.out.println("a");
        if (s.equals(sb)) System.out.println("b");
        if (sb.equals(s)) System.out.println("c");
    }
}

Select the one correct answer.

  1. The code will fail to compile since the constructor of the String class is not called properly.

  2. The code will fail to compile since the expression (s == sb) is illegal.

  3. The code will fail to compile since the expression (s.equals(sb)) is illegal.

  4. The program ...

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