Multiple choice technology programming languages

if("String".toString() == "String") System.out.println("Equal"); else System.out.println("Not Equal");

  1. Code will give compile time error

  2. Code will give runtime error

  3. Code will print "Equal"

  4. Code will print "Not Equal"

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

In Java, String's toString() method returns the same String object (this). The expression "String".toString() returns the literal "String" itself. Since it's the same literal, the == comparison returns true, so the code prints "Equal". The == operator compares object references for String, not content.