what ever the way u used for casting is correct way and for ur required
output you can change the derived class as follows:
class Derived extends Base
{
public String toString()
{
return ("i = " + i);
}
}
also instead of using these 3 steps for casting
Derived d = new Derived();
Base b ;
b = (Base)(d);
you can do it in a single step like
Base b=new Derived();
thats it over.