Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1149 :

Posted: Tue Aug 27, 2013 3:20 am
by Zoryanat
I thought interface cannot be instantiated, but the correct answer for this question is "MyInterface i =c" where MyInterface is name of interface that the object c Class is implementing. How is this possible? I obviously missing smth out, something obvious :/

Re: About Question enthuware.ocajp.i.v7.2.1149 :

Posted: Tue Aug 27, 2013 8:14 am
by admin
It is true that an interface cannot be instantiated but you are not instanciating any interface here. c points to an object of class C. So class C is instantiated (as given in the problem statement C c = new C();). Since C implements MyIFace, you can assign c to a reference of type MyIFace.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1149 :

Posted: Tue Aug 27, 2013 8:54 am
by Zoryanat
Thanks, Paul, that's explaining it. Cheers.