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

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

Moderator: admin

Post Reply
ETS User

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

Post by ETS User »

Explanation says :
The getValue(int i) method of class A in option c, is different than the method defined in the interface because their parameters are different. So this class does not actually implement the method of the interface and so it is declared abstract.

I'm assuming that getValue(int i) is in class B for the third option.
My question is when an abstract class implements an Interface, can it not implement the method in the interface..
ie in this question would it have been wrong if the third option was
abstract class B implements I1
{    
String getValue() { return "something"; }
}

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

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

Post by admin »

A class can be marked abstract even if it does not have any abstract method. If your code would be valid even if it implements all the methods of an interface.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

nmmedina
Posts: 3
Joined: Sat Nov 01, 2014 4:46 pm
Contact:

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

Post by nmmedina »

Regarding this partial explanation in option c, "...So this class does not actually implement the method of the interface and so it is declared abstract."

I can't figure out why the class has to be declared abstract. Why couldn't it be a non-abstract class? The method in option c is not an abstract method so why make the class abstract?

Thanks.

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

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

Post by admin »

If a class says that it implements an interface but doesn't actually define all the interface methods, then it has to be declared abstract.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

NickWoodward
Posts: 29
Joined: Mon Mar 30, 2015 6:00 pm
Contact:

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

Post by NickWoodward »

is it worth pointing out that option A wouldn't be correct even if it implemented the interface - because of default access in the methods?

the same could be said for option C (class B) - getValue(int i) isn't just incorrect because of the arguments, again it's got default access.

obviously the answers are correct, just thought that it might be worth pointing out (if i'm correct that is!)

nick

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

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

Post by admin »

Yes, that is a good point as well.
If you like our products and services, please help us by posting your review here.

tcroots19
Posts: 6
Joined: Tue Nov 19, 2019 2:01 pm
Contact:

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

Post by tcroots19 »

I see option C is not correct b/c of the parameter difference, but had that been the same and it truly implements `getValue`; isn't it also not correct b/c it does not implement `setValue`? Therefore it would still need to be abstract for that reason as well?

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

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

Post by admin »

Option 3 is this:

Code: Select all

abstract class B implements I1{
   int getValue(int i) { return 0; }
}
and is a correct option.
If you like our products and services, please help us by posting your review here.

tcroots19
Posts: 6
Joined: Tue Nov 19, 2019 2:01 pm
Contact:

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

Post by tcroots19 »

sorry, I typed that wrong. I meant to say Option 3 needs to be abstract (b/c it doesn't implement all methods from the interface), not that it is incorrect.

Is that correct?

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests