Difficulty: Easy
Correct Answer: A-2, B-3, C-4, D-1
Explanation:
Introduction:
Java differentiates between bitwise and logical operators, and it provides distinct symbols for exclusive OR and short-circuit logical operations. Mapping each operator to its meaning reinforces correct usage in expressions and conditionals.
Given Data / Assumptions:
Concept / Approach:
The single-ampersand & is bitwise AND for integer types (and a non-short-circuit boolean AND). The caret ^ is bitwise XOR (boolean XOR for booleans). The double-vertical-bar || is logical OR with short-circuit evaluation. The double-ampersand && is logical AND with short-circuit evaluation.
Step-by-Step Solution:
Verification / Alternative check:
Code trials show that || and && may skip the right-hand operand when left-hand decides the outcome, while & and ^ always evaluate both sides for booleans and operate bitwise on integers.
Why Other Options Are Wrong:
Swapping logical and bitwise semantics leads to subtle bugs, particularly from assuming & is short-circuiting.
Common Pitfalls:
Using & instead of && in conditionals (causes unintended evaluation); misunderstanding ^ as exponentiation (it is XOR in Java).
Final Answer:
A-2, B-3, C-4, D-1
Discussion & Comments