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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Zoryanat
Posts: 20
Joined: Tue Aug 27, 2013 3:16 am
Contact:

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

Post 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 :/

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Zoryanat
Posts: 20
Joined: Tue Aug 27, 2013 3:16 am
Contact:

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

Post by Zoryanat »

Thanks, Paul, that's explaining it. Cheers.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests