The scoping is different for the two variables. The one declared with in the class is the instance level and the one declared in the constructor is local to the constructor. The one in the constructor shadows the one in the class. You might want to read more about this by searching for "shadowing variables".
Campbell Ritchie wrote:You will get an error later if you try to use name and find it points to null.
1. That depends on how he tries to use it.
2. It won't point to null; it will hold the value null.
Sorry, couldn't help myself. :-)
Joined: Oct 13, 2005
He’s a she. She can’t use it; she can only do things which don’t mind its being null. Things like System.out.println(null); don’t so much use the nul as test for it and substitute the String "null" for it. Of course, you can always assign from it and spread the nice nullness throughout your whole application.
I’ve got to have the last word., haven’t I