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
πŸ’¬ Discuss
βœ… Correct Answer: (A) True
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.
Explanation by: Mayank
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
290
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Mayank
Publisher
πŸ“ˆ
86%
Success Rate