About Question enthuware.ocpjp.v8.2.1226 :
Moderator: admin
-
- Posts: 6
- Joined: Wed Jun 22, 2016 8:06 am
- Contact:
About Question enthuware.ocpjp.v8.2.1226 :
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?
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?
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1226 :
Interfaces do not have subclasses. The option is talking about forcing the subclasses to implement the methods.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Wed Jun 22, 2016 8:06 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1226 :
Thank you for the answer.
So can we consider the requirement "force subclasses to provide implementation" as implementation details?
So can we consider the requirement "force subclasses to provide implementation" as implementation details?
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1226 :
I am sorry but I don't understand what you mean by
"force subclasses to provide implementation" as implementation details.
If you like our products and services, please help us by posting your review here.
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
-
- Posts: 2
- Joined: Sun Mar 24, 2019 2:28 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1226 :
Hello!
I was thinking about option 2 or 4, but I was embarrassed at option 4 because of this situation:
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.
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 {};
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1226 :
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 19 guests