1 is obviously correct. as C4 is some unrelated class and they are declaring its inheritance relationships etc.
2 C3 is a subclass of C1, so o1=o3; would be ok. (if you do o3=o1 you need a cast like o3=(C3)o1; so NOT OK
3 o3=o2;NOT OK as you need a cast here again
4 I1 i1 = o3; C3 implements I1 (actually implicitly , as C3 extends C1, C1 implements I1 ,hence implictly C3 also implements I1) so OK
I2 i2=(I2)i1; since casting given it's fine
5 I1 b = o3; (as we said above C3 implements I1) so OK.
concepts
class
Test implements interface II
class Hello extends Test
references of II can denote objects of the class that implement this interface.
so II obj = new Test();
and since Hello is a subclass of Test so
II obj1 = new Hello(); (as class Hello also implictly implements interface II)
Originally posted by sonir shah:
Question :Given the following definitions and refernce declarations, which of these statements are legal?
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
class C3 extends C1 implements I2 { }
C1 o1;
C2 o2;
C3 o3;
Options :1)class C4 extends C3 implements I1,I2{}
2) o3=o1;
3) o3=o2;
4) I1 i1 = o3;I2 i2=(I2)i1;
5) I1 b = o3;
Answer is : 1,4,5
Can any one please explain me the above concepts..