0

Java programming trace the output?

What is the output of this code? String a=“a”; String b=“b”; String c=a+b; String d=“ab”; If(c==d) System.out.println(1); else System.out.println(0); Output is 0 why? Please solve my doubt!! because I lost this question in SoloLearn challenge.

7th Jul 2019, 11:25 AM
Anish Abhyankar
Anish Abhyankar - avatar
2 ответов
+ 2
'==' is a reference comparison. c and d has same value but different reference. So c.equals(d) will return true c==d will return false
7th Jul 2019, 12:04 PM
Odiesta Shandikarona
Odiesta Shandikarona - avatar
0
b
5th Apr 2024, 2:43 PM
Balu Rahane
Balu Rahane - avatar