Originally posted by Indraneel Das:
Hi all
class test{
public static void main(String args[]) {
String a = "A";
String b = "B";
final String c = a+b;
final String d = a+b;
System.out.print((c==c) + ",");
System.out.print(((a+b)==(a+b)) + ",");
System.out.print(c==d);
}
}
Indraneel
a+b evaluates at runtime.so, everytime u execute a+b it returns new string object. that is why (a+b)=(a+b) prints false.
But, in the below given code a and b are declared final.So, a+b evaluates at compile time and hence (a+b)=(a+b) prints true.
hope it helps.
regds
Arpana