What you are doing here is telling the JVM to create a brand new string "3", and change s3 to refer to it. the original string that s3 USED to refer to hasn't changed... if you print s1, it'll still print "1".
in other words, you can chage what string a reference points to, you can create new string, but you CAN'T change an old string.
Never ascribe to malice that which can be adequately explained by stupidity.
santosh kothapalli
Greenhorn
Joined: Dec 27, 2005
Posts: 26
posted
0
public class TimDig extends TimDigSuper{ //String device = "Mobile.device"; public static void main(String[] args) { String s1 = new String("D"); String s2 = "2"; String s3 = s1; s1.toLowerCase(); System.out.println(s1+s2+s3);///// }
} Try this and see ur doubt will be cleared as what immuteable means. cheers, Santu.
Santosh K<br />SCJP 1.4,SCWCD
Balaji Sampath
Ranch Hand
Joined: Sep 30, 2005
Posts: 63
posted
0
Hi there Just a doubt. Does the output for the above code is "321".. regards Balaji.S
Alejandro Montenegro
Greenhorn
Joined: Jul 05, 2004
Posts: 29
posted
0
try run it... but yes it gives 321
Isha Mackker
Greenhorn
Joined: Oct 18, 2005
Posts: 29
posted
0
Ya the output is 321 but what is being asked for is just s1, which is 3 only