Test Series - java

Test Number 21/64

Q: What happens to the Second operand/expression if the first operand is FALSE with a Short Circuit AND (&&) operator?
A. Second operand/expression is evaluated and AND is applied.
B. Evaluation of Second operand/expression is skipped.
C. The compiler starts taking more memory
D. The compiler starts taking more CPU power.
Solution: Whether it is normal AND operator or Short Circuit AND operator, both operands should be TRUE to give output as true. If the first operand itself is false, there is no point in evaluating the second expression.
Q: What happens to the Second Operand/expression if the first operand is TRUE with a Short Circuit OR (||) operator in Java?
A. Second expression/operand is evaluated and OR is applied to both operands
B. Evaluating the Second expression/operand is skipped
C. The compiler starts taking more memory
D. The compiler starts taking more CPU power
Solution: Both OR (|) and Short Circuit OR (||) operators give an output of true if at least one operand is true. Already the first operand is true. There is no need to evaluate or execute the second expression/operand.
Q: What is the output of an Exclusive OR (^) operation if one of the operands/expressions is TRUE?
A. false
B.  true
C. true or false
D. None of the above
Solution: Exclusive OR (^) gives an output of true if both the operands are different. If both are the same (true / false), the output is false. So, with just one operand, you can not decide the output.
Q: What is the output of an Exclusive OR(^) operation, if one of the operands is false?
A. false
B. true
C. true or false
D. None of the above
Solution: Exclusive OR (^) gives an output of true if both the operands are different. If both are the same (true / false), the output is false. So, with just one operand, you can not decide the output.
Q: Which is the Logical operator in Java that has the highest priority among all other logical operators?
A. Short Circuit AND (&&)
B. AND (&)
C. NOT (!)
D. Exclusive OR (^)
Solution: no solution
Q: Among the Logical operators, AND (&) and Short Circuit AND (&&), which has higher priority?
A. AND (&)
B. Short Circuit AND (&&)
C. Both have same priority
D. None of the above
Solution: no solution
Q: Among the logical operators, OR (|) and Short Circuit OR (||), which operator has higher priority?
A. OR (|)
B. Short Circuit OR (||)
C. Both have the same priority
D. None of the above
Solution: no solution
Q: Among the logical operators, OR (|), Short Circuit OR (||) and Exclusive OR (^), which operator has higher priority?
A. OR (|)
B. Short Circuit OR (||)
C. Exclusive OR (^)
D. All operators have the same priority.
Solution: ! >
& >
^ >
| >
&& >
|| >
Assignment
Q: Choose the correct version of Logical Compound Assignment operators in Java below?
A. &=, |=, ^=
B. &&=, ||=, !=
C. A and B
D. None of the above
Solution: There no logical compound assignment operators like &&=, ||=, !=.
Q: What is the output of the Java code snippet below?
byte a= 1;
if(!a)
{
  System.out.println("FISH");
}
else
{
  System.out.println("CRAB");
}
A. CRAB
B. FISH
C. Compiler error
D. None of the above
Solution: You can not convert from byte to boolean.


The operator ! is undefined for the argument type(s) byte

You Have Score    /10