Many times you are not able to tell exactly which class will be instantiated, until the runtime. In these situations you want to be able to create an object through some identifier such as the name of the class. This is one of the abilities that Reflection API of Java provides.
It is legal and sometimes necessary to cast a derived class pointer into base class pointer. This is also called upcast but by doing so the type information of the pointer gets lost.