equals and == difference

India
August 1, 2007 3:19am CST
String s1=new String("abc") String s2=new String("abc") String s3="abc"; String s4="abc"; wht is output when s1=s2; s2=s3; s3=s4; s4=s1;
1 person likes this
4 responses
@zaroff (14)
• Spain
7 Aug 07
Error.
• India
14 Aug 07
hi.... sory to all s1=s2; == System.out.println(s1==s2); similarly to all the statements
@dj_faheem (738)
• Pakistan
9 Sep 07
first of all that s1=s2; s1==s2 seond one is if u consider s1==s2; s2==s3; s3==s4; s4==s1; when s1==s2--output abc when s2==s3---output is not abc coz both string define in diff methods when s3==s4---output abc when s4==s1----output is not abc coz both string define in diff methods
@mr_mlk (364)
2 Aug 07
Run it. Nothing. You are assigning variables, and you have no output. equals checks that the content is "identical". == checks that the two refrences point to the same object.
@mnvamsi (539)
• India
4 Aug 07
for the above programme if u print the values if s1,s2,s3,s4 the output is nothing more than "abc" but if you compare like this s1==s2;s2==s3;s3==s4;s4==s1; n print the values of s1,s2,s3,s4 this will cause in 4 errors i.e "s1==s2 is not a statement" 4 errors like this..