+ 2

Can any one explain why the output of this code is '0' (zero)?

public class Program { public static void main(String[] args) { 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"); } } }

28th Oct 2017, 10:00 PM
Mr. Pool
Mr. Pool - avatar
1 Answer
+ 6
== compare references and not valued, use. equals() instead
28th Oct 2017, 10:15 PM
Maher Zaidoune
Maher Zaidoune - avatar