Given the following definitions and reference declarations:
interface Interface1 { } interface Interface2 { } class MyClass1 implements Interface1 { } class MyClass2 implements Interface2 { } class MyClass3 extends MyClass1 implements Interface2 { } MyClass1 o1; MyClass2 o2; MyClass3 o3;
Which of these statements are legal?
Select 3 options
Correct Options are : A D E
For Option A.
The implements Interface1, Interface2 is redundant here because MyClass3 already implements Interface1 and Interface2, it is not invalid.
For Option B.
superclass reference cannot be assigned to subclass reference without explicit cast.
For Option C.
There is no way a reference of class MyClass2 (which is o2) can point to an object of class MyClass3 because MyClass2 and MyClass3 have no inheritance relationship.
So this assignment is rejected at compile time itself.
For Option D.
This is valid because at run time i1 actually refers to an object that implements Interface2.
For Option E.
Because MyClass3 extends MyClass1 which implements Interface1.