Page 1 of 1

About Question enthuware.ocpjp.v8.2.1226 :

Posted: Wed Jun 22, 2016 8:18 am
by lexer24
Hi,

Why option 4 - You want to define common method signatures in the class but force subclasses to provide implementations for such methods. is valid here?

In question enthuware.ocpjp.v8.2.1229, description for option 1 is - This is a valid reason for declaring an interface but not an abstract class. Generally, the purpose of an interface is to identify and declare just the behavior. Actual implementation can come later. While abstract class is used when a common implementation is also identified. In that respect, an abstract class actually provides less abstraction than an interface.
From this explanation comes that if we have just signatures and no common implementation it is better to use interface and not an abstract class.

Maybe it should be - You want to define common method implementation in the class but force subclasses to provide specific implementations for such methods instead? Or a sort of this?

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Wed Jun 22, 2016 8:32 am
by admin
Interfaces do not have subclasses. The option is talking about forcing the subclasses to implement the methods.

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Tue Jul 12, 2016 4:27 am
by lexer24
Thank you for the answer.

So can we consider the requirement "force subclasses to provide implementation" as implementation details?

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Tue Jul 12, 2016 4:38 am
by admin
I am sorry but I don't understand what you mean by
"force subclasses to provide implementation" as implementation details.

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Fri Mar 15, 2019 2:08 pm
by crazymind
admin wrote:
Wed Jun 22, 2016 8:32 am
Interfaces do not have subclasses. The option is talking about forcing the subclasses to implement the methods.

How do we call a class who implements an interface? This question is really tricky.

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Tue Apr 02, 2019 3:37 pm
by ncskiber
Hello!

I was thinking about option 2 or 4, but I was embarrassed at option 4 because of this situation:

Code: Select all

abstract class A {
     abstract void test ();
}

abstract class B extends A {};
Here “B” is a subclass of “A”. And "B" is also an abstract class that is not obliged to implement the method of the superclass "A". In other words, this is true for the first concrete subclass. The question was not precise wording.

Re: About Question enthuware.ocpjp.v8.2.1226 :

Posted: Tue Apr 02, 2019 11:33 pm
by admin
It is only talking about a necessary condition (and not a sufficient one). If you want to define common method signatures in the class but force subclasses to provide implementations for such methods then you definitely need an abstract class. Having an abstract class may not be sufficient though.