20. Which of the following statements about unary operators are true? (Choose all that apply.)
A. Unary operators are always executed before any surrounding binary or ternary operators.
...
A, D, E. Unary operators have the highest order of precedence, making option A correct. ...
Best Regards
Samuel Silver Moos
If a unary operator and a binary or ternary operator are both executed on the same operand, the unary operator is executed first.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
I presume you mean the lion and tiger question. I thought I had persuaded them to keep it in. The fact that everybody who doesn't know the order of execution gets it wrong makes it a good question. Remember that cert exaams test your knowledge of the rules, not your ability to write good code. And if we start with x as 5, what would the value of x be after your obfuscated code?Jesse Silverman wrote:. . . one of the examples that Scott and Jeanne decided to remove from any future versions of the book because it confused people . . .
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
There are a large population of book reviewers who think every book is a beginner's tutorial and mark them like that. I think that means they didn't read it properly.Jesse Silverman wrote:. . . The negative reviews said "You could read this whole book and not learn how to do one thing in Java you didn't already know how to do." . . .
Campbell Ritchie wrote:Welcome to the Ranch
![]()
I think I agree with you. The answer was right and the question was, well, at least not clear. I think it would read better as something like this:-If a unary operator and a binary or ternary operator are both executed on the same operand, the unary operator is executed first.
Best Regards
Samuel Silver Moos
?x = x++x++x++x++;
Campbell Ritchie wrote:Somebody should have read the list of operators, then they would have known that ^ isn't a power operator. What was the intention behind 1 | 2? Was somebody trying to catch both possibilities? Of course the compiler won't notice. 1 | 2 is a compile‑time constant and the compiler will simply convert that to 5. And all's tickety‑boo. Remember no compiler can detect incorrect logic.
Except for my deliberate error, which I am trusting you to find.
JS: what did you get from
x = x++x++x++x++;
?
Best Regards
Samuel Silver Moos
It is 26...I was already perceived to be an OCD precedence-memorizer, and I sometimes get these wrong....if I ever got THAT one wrong I don't expect it to happen again...
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Best Regards
Samuel Silver Moos
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Campbell Ritchie wrote:It's rather old fashioned but definitely commoner in Britain.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
And inside of my fortune cookie was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|