Home / Programming MCQs / JAVA MCQs / Question

Q. What is the output of the following code snippet?

Code:
String s1 = “Hello”;
String s2 = new String(“Hello”);
System.out.println(sA)equals(s2));
(A) True
(B) False
(C) Error
(D) None of these

Explanation:

The equals method in Java checks if two strings have the same value. In this case, s1 and s2 both have the value “Hello”, so sA)equals(s2) returns true.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.