This question is regarding an answer on a question in one of the chapter review questions in the book: OCP Oracle Certified Professional Java SE8 Programmer II Study Guide by Jeanne Boyarsky and Scott Selikoff.
The question goes as follows (page 319):
10. Which of the following are true of the code? (Choose all that apply.)
A. Line 5 does not compile.
B. Lines 6 and 7 do not compile because they are missing the String message.
C. Lines 6 and 7 do not compile because they are missing parentheses.
D. Line 6 is an appropriate use of an assertion.
E. Line 7 is an appropriate use of an assertion.
I answered A, but the explanation of this question (page 560) goes as follows:
A, E. Line 5 does not compile because assert is a reserved word making Choice A correct. B and C are incorrect because the parenthesis and message are both optional. D is incorrect because assertions should not have side effects. E is correct because checking an argument passed from elsewhere in the program is an appropriate use of an assertion.
I do not understand why E is correct. To me it seems as if is the same as Can anyone explain me the difference and how the authors came to this answer?
Those two lines are different because one has "side effects." The one with variable "a" changes the value of "a" when it runs. The one with variable "b" does not. As the book discusses, it is not acceptable practice to have assert statements change the value of data.