Hi Friends, This question is from Dan's Questionaire,i am not able to understand the wordings,can you please tell me what the author means to convey here,and how can the error be removed from this code.Thanks.
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