1st code Starts
2nd code starts
2nd code 1st class starts
2nd code 2nd class starts
We know that
String is also an object and the name of the string variable is just a reference to that object.Then Why both these codes behave differently??.
In 1st code , the String value or data stored in the object does not changes in output whereas in 2nd code the object data gets changed.