Question
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 is the output of this program?
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));
}
}
Answer: Option D
Was this answer helpful ?
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:
$ javac output.java
$ java output
false true
Was this answer helpful ?
More Questions on This Topic :
Question 5.
Which of these is an oncorrect statement?
....
Submit Solution