Page 1 of 1

About Question enthuware.ocpjp.v7.2.1399 :

Posted: Tue Jan 13, 2015 7:46 am
by Svetopolk
Case 2: This code will not work in all situations
Explanation: It will not work if assertions are disabled.

Why? I don't know for sure what the code does.
Probably it only prints PhoneNumber. And it will work even number==null or length() != 10

Or we can assume that the code really doesn't work properly if number==null. But it doesn't work in any circumstances: NPE or AssertionError - not a big deal.

I think we can't predict how ON/OFF assertion will influence on.

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

Posted: Tue Jan 13, 2015 9:25 am
by admin
Well, the problem statement says what the programmer wants to achieve, "...to ensure that the phone number is not null and is of 10 characters". It also shows the code that the programmer has written so you know what the code does.

The code will work fine if assertions are enabled but it will not do what is expected if assertions are disabled.

HTH,
Paul.

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

Posted: Thu Jan 21, 2016 7:16 am
by toolforger
Typo: Last option is "Constraints on input parameters should be enforced using assersions."
Last word should be "assertions".

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

Posted: Thu Jan 21, 2016 9:00 am
by admin
Fixed.
thank you for your feedback!