About Question enthuware.ocpjp.ii.v11.2.3360 :

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

Moderator: admin

Post Reply
kabanvau
Posts: 14
Joined: Thu Nov 21, 2019 5:48 am
Contact:

About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by kabanvau »

Hi,
Several similar default methods need to be added to this interface and each method is supposed to log a message at the start of the method. As of now, the logging is done using just a println statement but it may change later.
The right answer was:

Add a private void log(String msg) method


How do you want to change it later? It is private. The method will always do logging using a println statement.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by admin »

The requirement is to make the interface more maintainable. Putting a private void log(String msg) in this interface and invoking this method from all default methods instead of having a sop statement in the methods will make it more maintainable because now you just need to change the log method to use whatever mechanism you want to use to log the message.

Without this method, you would have to make the change in every default method.
If you like our products and services, please help us by posting your review here.

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by sohamdatey22 »

How is first option, even going to compile?
The explanation for first one is incorrect, interfaces do not allow public instance like methods, they do allow public default method, or a private instance methods, or public static, or private static

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

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by admin »

Why would it not complile??
All methods of an interface are instance methods (unless you explicitly define them as static). This option is talking about having such a method. Since it is an abstract method, a class that implements this interface will have to implement it. It is a valid approach but not a good approach and the explanation is correct.
If you like our products and services, please help us by posting your review here.

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by sohamdatey22 »

Where does it say its abstract method, it also is stating that, it will log, some message, indicating the presence of body.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by admin »

Interface methods are, by default, abstract unless explicit made not so.
Also, the option is not giving the complete code. It is talking about an approach. It is a valid approach but not appropriate for reasons explained.
See, you can split hair here but it would be more beneficial if you focus on the concept.
If you like our products and services, please help us by posting your review here.

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3360 :

Post by sohamdatey22 »

Aye, Aye, Captian.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests