Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String s1 = “Hello i love java”;
String s2 = new String(s1);
System.out.println((s1 == s2) + ” ” + s1.equals(s2));
}
}

What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String s1 = “Hello i love java”;
String s2 = new String(s1);
System.out.println((s1 == s2) + ” ” + s1.equals(s2));
}
}
a) true true
b) false fals
c) true false
d) false true

Answer: d
Explanation: The == operator compares two object references to see whether they refer to the same instance, where as equals() compares the content of the two objects.
Output:
false true

Join The Discussion