Multiple choice

What will be the output of the program? public class Test178 { public static void main(String[] args) { String s = "foo"; Object o = (Object)s; if (s.equals(o)) { System.out.print("AAA"); } else { System.out.print("BBB"); } if (o.equals(s)) { System.out.print("CCC"); } else { System.out.print("DDD"); } } }

  1. AAACCC

  2. AAADDD

  3. BBBCCC

  4. BBBDDD

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

In Java, String.equals(Object) works correctly because String's equals method overrides Object.equals to handle String comparison. Both s.equals(o) and o.equals(s) return true because they reference the same String object 'foo'. The equals method checks for actual content equality, not reference equality.