Page 1 of 1

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

Posted: Fri Dec 06, 2019 9:02 am
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.

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

Posted: Fri Dec 06, 2019 11:20 pm
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.

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

Posted: Sun Oct 02, 2022 1:27 pm
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

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

Posted: Sun Oct 02, 2022 11:15 pm
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.

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

Posted: Tue Oct 04, 2022 12:04 am
by sohamdatey22
Where does it say its abstract method, it also is stating that, it will log, some message, indicating the presence of body.

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

Posted: Tue Oct 04, 2022 12:52 am
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.

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

Posted: Tue Oct 04, 2022 11:27 am
by sohamdatey22
Aye, Aye, Captian.