What will be the result of attempting to compile and run the following program?

1.5 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";
StringBuilder sb = new StringBuilder(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");
}
}
}
A) The code will fail to compile because the constructor of the String class is not called properly.
B) The code will fail to compile because the expression (s == sb) is illegal.
C) The code will fail to compile because the expression (s.equals(sb)) is illegal.
D) The program will print c, when run.


Leave a Reply