Multiple choice technology programming languages

What is the result of compiling and running the following code? String s=new String("hello"); StringBuffer sb=new StringBuffer("hello"); System.out.println(s.equals(sb));

  1. Compiler error: String and StringBuffer objects cannot be compared

  2. ClassCastException: String and StringBuffer objects cannot be compared

  3. Prints "true"

  4. Prints "false"

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The equals method in the String class checks if the compared object is an instance of String. Since sb is a StringBuffer, the comparison immediately returns false without comparing their character contents.