String s1 = "abc"; String s2 = new String("abc"); String s3 = "abc"; System.out.println(s1 == s2); System.out.println(s1 == s3); System.out.println(s1 == "abc");
String literals refer to the same instance of the String class. Therefore s1 == s3 and s1 == "abc" comparisons will result in true.
New instance of the class is created with the new operator, therefore s1 == s2 will result in false.
Login in to like
Login in to comment
or Read more about Java Quizzes
Login in to like
Login in to comment