This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Q:An unary operator operates on a single value 1.True 2.False The answer is given as False,bcos + and -,can take two values. Since,+ and - can be used both as unary and binary operator,what would be the best possible explanation in this context?
The same symbols are used for unary operators: +variable -variable as for additive operators: var1 + var2 var1 - var2 I disagree with the answer. Because additive operators are not unary ones. Though they share the same symbols.
SCJP2. Please Indent your code using UBB Code
Joined: Jul 13, 2001
When '+' or '-' is used as a unary operator,it acts only on a single value,right. So,the answer should be true. There was another question about operands : Q:All operands r evaluated left to right. 1.true 2.false. The answer is given as true.Will the precedence and associativity rules not apply? Pl.clarify.
Joined: Jul 03, 2001
After the operands are evaluated, the operations are performed based on the precedence of the operators (and parentheses). Associativity plays a rol when considering operators with the same precedence. Please see an example JLS deals with Evaluation Order