Consider this line,
Test1 t2 = t1.print();//wrong code
You have to explicitly typecast in this situation.
Test1 t2 = (Test1)t1.print();//correct code
You have to explicitly typecast in case of narrowing conversion(Parent class—>child class)
Your compiler automatically typecasts in widening conversions(Child class—>Parent class).
3
solved Here is a simple java code giving an error may i know why so