Java Assertions Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of operators and assignments in Java, including arithmetic, relational, logical, bitwise, assignment, unary, conditional, and shift operators, along with operator precedence and type conversions.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. %
The modulo operator (%) returns the remainder after division. For example, 10 % 3 evaluates to 1.
A. 5
The postfix increment operator returns the current value before incrementing the variable. The expression prints 5, and x becomes 6 afterward.
C. ==
The == operator compares primitive values for equality. For reference types, it compares object references rather than object contents.
D. false
The logical AND operator (&&) evaluates to true only when both operands are true.
B. +=
The += compound assignment operator adds the right-hand value to the variable and stores the result back in that variable.
C. 15
The statement x += 5 is equivalent to x = x + 5 in this example, so x becomes 15.
A. ||
The || operator evaluates the right operand only if the left operand is false.
D. 10
The conditional operator evaluates the condition first. Since 5 > 3 is true, the expression returns 10.
B. ^
The ^ operator performs bitwise exclusive OR on integral operands, producing 1 for each bit position where the corresponding bits differ.
C. 4
The signed right-shift operator moves the bits one position to the right. For the positive integer 8, shifting right by one produces 4.
A. *
Multiplication has higher precedence than addition, equality comparison, and logical OR.
D. 8
The prefix increment operator increments x before producing the value of the expression, so the code prints 8.
B. = assigns a value, while == tests equality
The assignment operator (=) stores a value in a variable, whereas the equality operator (==) compares values or reference identities.
C. 2
In binary, 6 is 110 and 3 is 011. Their bitwise AND is 010, which equals 2.
A. x becomes 2
Both operands are integers, so Java performs integer division and discards the fractional part. The result is 2.