A good answer might be:Yes. | ||
Non-short-circuit Operator
The & operator combines two boolean values using the rules for AND, but always evaluates both operands. This is useful when you want both operands to be evaluated no matter what values are returned. The disadvantage is a potential loss of speed. Most Java programs are written using the && operator whenever an AND is needed. The programmer must be careful of side-effects, though. Usually this is done by writing methods that are "pure functions" as much as possible. A pure function is a method that returns a value and is free of side effects. Methods that are not pure functions should usually be kept out of boolean expressions. For example, the method computeMaximum() in the previous example is not a pure function. It would be better if it computed the maximum, but did not itself save the result. Then the program fragment could be written like this: Now there is no danger from side-effects and it is clear where maximum is set.int maximum; . . . maximum = computeMaximum(); if ( sum < 100 && maximum < 500 ) . . . result = 2 * maximum ; | ||
QUESTION 5:What does the following print?
Click Here after you have answered the question
|