Pick me! Pick me! (I had to track it down after all, Jason just knew it.)
Since no one else has jumped at this, I'm going for it. OK Jason?
For the first case (A):
From the API java.io.PrintWriter or java.io.PrintStream for the method println(Object obj):
println( Object obj) "behaves as if it invokes print(obj) and then println()."
The method print( Object obj) returns the
string produced by String.valueOf( Object obj ).
So in turn, the method String.valueOf( Object obj) "returns the string representation of the Object argument."
Here's the nuance. Just exactly what it returns depends on the argument:
"if the argument is null, then the string equal to "null" ; otherwise, the value of obj.toString() is returned."
For the second case (B):
The value of the variable here named object is null, which means it is a reference to nothing, since null is used to indicate the absence of an object. There is no object on which to call an instance method, in this case toString(); hence the NullPointerException.
.....
A side note...
As someone who prefers reading the printed page to starting the computer and reading from the screen, I went and looked at 6 (count 'em 6!) different books before giving up and going to the API. 5 minutes later there it was.
Have to work on changing my habits and going to the API
first.
[ April 13, 2002: Message edited by: Pauline McNamara ]