Hi, what about the code below:
It compiles well but throws NullPointerException at ////A at
runtime, anyone has better idea? If I change it into:
It will compile and run well. Why? In my opinion, the two
should be the same.
Thanks
Guoqiao
Originally posted by Jyotsna Clarkin:
[B]
Here t1 is created with i = 0
and when you print it
it checks the toString() method
and prints null.
Similarly t2 prints 2 because value of i is 2 and toString() returns i. [/B]
Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum