I didn't understand why this example works fine
<code>
public class Test009 extends T
{
public static void main(
String args[])
{
Test009 t = null;
T tt = (T)t;
System.out.print(t);
System.out.print(" ");
System.out.println(tt);
}
}
class T{}
</code>
And this one giver nullPointerException when runs??
<code>
class Test001
{
int i;
public Test001(int i) { this.i = i; }
public String toString()
{
if(i == 0) return null;
else return "" + i;
}
public static void main(String[ ] args)
{
Test001 t1 = new Test001(0);
Test001 t2 = new Test001(2);
System.out.println(t1);
System.out.println(t2);
}
}
</code>
Can anyone explain me that?!