about enthuware.ocpjp.ii.v11.2.3359

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

Moderator: admin

Post Reply
codeappman@gmail.com
Posts: 3
Joined: Fri Sep 20, 2019 11:53 am
Contact:

about enthuware.ocpjp.ii.v11.2.3359

Post by codeappman@gmail.com »

why the 2nd option is not correct?

2) Device should implement Closeable and override close() method // why this is not correct?
5) Device should implement AutoCloseable and override close() method. // answer said only this is correct

Closeable extends AutoCloseable, implementing either of them is valid for try-with-resources. I think the 2nd option is also valid.

Thanks.

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

Re: about enthuware.ocpjp.ii.v11.2.3359

Post by admin »

The requirement for a try with resource block is AutoCloseable and not Closeable.
If the problem statement were asking about interfaces that may be implemented then Device, the Closeable would have been correct as well. But the problem statement says "should implement". There is no requirement for Closeable. It should implement only AutoCloseable.

Further, since only one option is required to be selected, AutoCloseable is the best option.
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: about enthuware.ocpjp.ii.v11.2.3359

Post by floryan »

So the argumentation here is that AutoCloseable is newer/better and hence SHOULD be implemented rather than Closeable?

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

Re: about enthuware.ocpjp.ii.v11.2.3359

Post by admin »

No, as mentioned in the above response, the argument is that the requirement for a try with resource block is AutoCloseable and not Closeable. So, that is what you should implement.
Try with resource doesn't care about Closeable and should not be implemented if it is not required for other reasons.
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: about enthuware.ocpjp.ii.v11.2.3359

Post by floryan »

Sorry, I got confused there. Thanks for the explanation.

Post Reply

Who is online

Users browsing this forum: No registered users and 89 guests