Page 1 of 1

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

Posted: Wed Feb 20, 2013 9:07 pm
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"; }
}

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

Posted: Thu Feb 21, 2013 7:41 am
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.

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

Posted: Mon Nov 03, 2014 11:26 pm
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.

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

Posted: Tue Nov 04, 2014 12:19 pm
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.

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

Posted: Mon Feb 15, 2016 2:50 pm
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

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

Posted: Mon Feb 15, 2016 8:15 pm
by admin
Yes, that is a good point as well.

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

Posted: Wed Nov 20, 2019 6:56 am
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?

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

Posted: Wed Nov 20, 2019 7:02 am
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.

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

Posted: Wed Nov 20, 2019 12:09 pm
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?