One thing
you should always remember is that Strings are always objects in Java.People usually get confused about the difference between Objects and references.
Here are some differences:
1) A reference is located in the stack memory, while an object is in the heap.
2) A reference is NOT an object.
3) We use references to
refer to objects
4) Objects are eligible for garbage collected, when they loose their reference.
5) Objects are created using the new keyword.
Now, back to your question...
String str = new String();
str --> (String)
In this case you have a reference that is named 'str' which is referring to a string object.
String str1 = null;
str1 --> null
Here on the other hand, you have a reference called 'str1' that is supposed to refer to an object of type string, but it is not, it is referring to null (Which mean that there is no object).
Since both str and str1 have the same referene, then they will have the same methods.
[ May 16, 2004: Message edited by: Vicken Karaoghlanian ]