In the below problem if i comment out the line at (3) there is no exception thrown but if i uncomment it then it gives a exception.
Will casting of a parent object to child object give a error at runtime?
class CastingExA {}
class CastingExB extends CastingExA {}
public class CastingEx {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
CastingExA[] arrA;
CastingExB[] arrB;
arrA = new CastingExA[10];
arrB = new CastingExB[20];
arrA = arrB; // (1)
arrB = (CastingExB[]) arrA; // (2)
arrA = new CastingExA[10];
arrB = (CastingExB[]) arrA; // (3)
}
}