Page 49. Says Strings are special objects in Java.
'They are immutable' you can't change the value of a String that has been initialized.
Does it mean the compiler will allow it...but unexpected behaviour may occur in run-time.. Why the compiler stop from compiling
Below compile/with allowable changing of String objects :-
public class MyString {
String mystr = "Mary";
public static void main(String args[]) {
MyString mystring = new MyString();
System.out.println( mystring.mystr);
mystring.mystr = "Smith, Mary";
System.out.println( mystring.mystr);
}
}
Output
Mary
Smith,Mary
