interface I1 {}
interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Silver
{
public static void main(String []args)
{
Base[] base = {new Base()};
Sub sub[] = new Sub[1]; // 1
Object obj = base; // 2
sub = (Sub[])obj; // 3
I1 []i1 = (I1[])obj; // 4
}
}
Actually at the compile time it will allow , as we are implicit downcasting.
But at the run time it will check for the actual object in this case the actual object refered by obj is of Base type that's why it will give error . To remove the change
Object obj = sub; // 2