String s = new String("Hi");
String s1 = new String("Hello");
String s2 = "Hi";
The total number of object are 4 . Right ?
2 object on string literal pool .
2 object on garbage collection heap .
s is a reference variable that is pointing to an object that is on GCH & that object is poining to an object of SLP that has string literal Hi
s1 is a reference variable that is pointing to an object that is on GCH & that object is poining to an object of SLP that has string literal Hello
s2 is a reference that is directly pointing to the same object of SLP that has string literal Hi
Am I Right in everything ???
thanks .
[ January 08, 2005: Message edited by: rathi ji ]