About Question enthuware.ocpjp.v7.2.1226 :

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

Moderator: admin

Post Reply
tduglas
Posts: 6
Joined: Wed May 22, 2013 4:03 am
Contact:

About Question enthuware.ocpjp.v7.2.1226 :

Post by tduglas »

Why the answer "You want to define common method signatures in the class but force subclasses to provide implementations for such methods." is correct and not "You need to provide generic implementation that can be overridden by the subclasses."?

"You want to define common method signatures in the class but force subclasses to provide implementations for such methods." - this can be done with an interface also.

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

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

Post by admin »

1. If you provide a generic implementation, how will you force the subclass to provide implementation?
2. Yes, it can be done with interfaces but the question is talking about class and subclass.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

tduglas
Posts: 6
Joined: Wed May 22, 2013 4:03 am
Contact:

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

Post by tduglas »

admin wrote:1. If you provide a generic implementation, how will you force the subclass to provide implementation?
The answer tells that implementation can be overridden ("You need to provide generic implementation that can be overridden by the subclasses."), but not that you should force the override. Abstract class suite this, because one can provide generic implementation in it's methods, right?
Maybe, I misunderstood the question.
admin wrote:2. Yes, it can be done with interfaces but the question is talking about class and subclass.
Ok.

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

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

Post by admin »

The question asks, "In which of the following scenarios will you need to create an abstract class?"

The correct option says, "You want to define common method signatures in the class but force subclasses to provide implementations for such methods."

To force a subclass to provide an implementation, you need to make the method in the superclass abstract. So this is a good reason to use an abstract class.

If you do not have abstract method in a class, you do not need an abstract class. So if you provide generic implementations for the methods in a class, you don't need to make it abstract. Thus, option 2 is not correct.

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

tduglas
Posts: 6
Joined: Wed May 22, 2013 4:03 am
Contact:

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

Post by tduglas »

admin wrote:If you do not have abstract method in a class, you do not need an abstract class.
Got it now.

Ambiorix
Posts: 25
Joined: Thu Jan 10, 2013 8:45 am
Contact:

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

Post by Ambiorix »

You want to define common method signatures in the class but force subclasses to provide implementations for such methods.
If I also declare the subclass as abstract it's not forced to provide any implementation for the methods. Shouldn't the correct answer say 'force non-abstract subclasses' rather than just 'force subclasses'?

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

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

Post by admin »

Yes, what you are saying is correct but I think you are taking it to the extreme. The question is really simple, if the objective of the superclass is to force a subclass to override a method, then the what do you do? You make the method abstract. Of course, if the subclass itself is abstract then the whole point is moot.

But again, you are technically correct.
If you like our products and services, please help us by posting your review here.

smartinez
Posts: 1
Joined: Thu May 29, 2014 3:39 pm
Contact:

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

Post by smartinez »

I think the benefit of abstract classes is not only that you can force subclases to implement methods (that can be done with interfaces), and not only that you can give generic implementation for some methods that can be overriden (that can be done with concrete classes), but that you can do both thing at the same time.

Statics
Posts: 6
Joined: Sat Aug 10, 2013 1:54 pm
Contact:

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

Post by Statics »

I was confused with the question too. Exactly because "generic implementation" and "forcing subclasses to provide implementations fro some methods" are both benefits of using abstract classes and I was thinking like:
1) "You need to provide generic implementation that can be overridden by the subclasses." - yes, an abstract class does this, but a regular class can as well
2) "You want to define common method signatures in the class but force subclasses to provide implementations for such methods." - yes, an abstract class does this, but an interface can as well

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests