You have to make the following change in the code:
class T1{}
class T2 extends T1{}
class T3 extends T1{}
public class Test{
public static void main(String []arg)
{
T1 t1=new T1();
T2 t2=new T2();
T3 t3=new T3();
t1=t2;//line1
t2=(T2)t1; //line 2
}
}
See at line 2 t1 is typecasted to T2...
Type of the actual objet denoted by reference at runtime, is checked...
In your program the reference t1 was denoting objet of class T1..
Now in the above program at runtime, reference t1 is denoting objet of type T1...so no runtime exception..
Hope this clears....