Multiple choice technology

If you compile and execute an application with the following code in its main() method: String s = new String( "Computer" ); if( s == "Computer" ) System.out.println( "Equal A" ); if( s.equals( "Computer" ) ) System.out.println( "Equal B" );

  1. It will not compile because the

  2. "Equal A" is the only thing that is printed

  3. "Equal B" is the only thing that is printed

  4. Both "Equal A" and

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

The == operator compares object references, not content. Since new String("Computer") creates a distinct String object in memory, s == "Computer" is false (they point to different objects). The equals() method compares actual string values, so s.equals("Computer") is true, printing "Equal B".