This is question form MarcusGreen's Mock exam 2. interface IFace{} class CFace implements IFace{} class Base{} public class ObRef extends Base{ public static void main(String argv[]){ ObRef ob = new ObRef(); Base b = new Base(); Object o1 = new Object(); IFace o2 = new CFace(); } } 1)o1=o2; 2)b=ob; 3)ob=b; 4)o1=b;
My question is under what circumstances the casting from an Interface to Object is possible and vice versa. Any thoughts are greatly appreciated. Thanks
Vanitha Sugumaran
Ranch Hand
Joined: Apr 11, 2001
Posts: 356
posted
0
I guess the question is about one of these causing compiler error. o1=o2; //works fine since o1 is type of Object b=ob; //Assign subclass to super class fine ob=b; //Error, can't assign super class to sub class //cast needed o1=b; //fine
My question is under what circumstances the casting from an Interface to Object is possible and vice versa. Any thoughts are greatly appreciated.