About Question enthuware.ocajp.i.v7.2.1149 :
Moderator: admin
-
- Posts: 20
- Joined: Tue Aug 27, 2013 3:16 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1149 :
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 :/
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1149 :
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.
HTH,
Paul.
-
- Posts: 20
- Joined: Tue Aug 27, 2013 3:16 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1149 :
Thanks, Paul, that's explaining it. Cheers.
Who is online
Users browsing this forum: No registered users and 8 guests