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.
About Question enthuware.ocpjp.v7.2.1399 :
Moderators: Site Manager, fjwalraven
-
- Posts: 22
- Joined: Sun Nov 18, 2012 1:51 am
- Contact:
-
- Site Admin
- Posts: 10401
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1399 :
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.
The code will work fine if assertions are enabled but it will not do what is expected if assertions are disabled.
HTH,
Paul.
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1399 :
Typo: Last option is "Constraints on input parameters should be enforced using assersions."
Last word should be "assertions".
Last word should be "assertions".
-
- Site Admin
- Posts: 10401
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1399 :
Fixed.
thank you for your feedback!
thank you for your feedback!
Who is online
Users browsing this forum: No registered users and 3 guests