Multiple choice technology programming languages

What will happen when you attempt to compile and run the given code? 1. public class EqualsTest 2.{ 3. public static void main(String[] args) 4.{ 5. Boolean b = new Boolean(true); 6. String str = new String(""+b); 7. StringBuffer buff = new StringBuffer(str); 8. 9. System.out.println(b.equals(str) + ", " + 10. str.equals(buff) + ", " + 11. buff.equals(b)); 12. } 13. }

  1. It will print - false, true, false

  2. It will print - true, true, false

  3. It will print - false, false, false

  4. It will print - true, false, false

  5. Compilation error

  6. ClassCastException at runtime

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

b.equals(str) is false because Boolean.equals() returns false when comparing to a String. str.equals(buff) is false because String.equals() returns false when comparing to StringBuffer. buff.equals(b) is false because StringBuffer doesn't override equals() to compare with Boolean. Result: 'true, false, false'.