AP Computer Science A Practice Quiz: Comparing Boolean Expressions
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 14 questions to check your progress.
Question 1 of 14
All Questions (14)
A) They use the same variables and operators.
B) They evaluate to the same value in all cases.
C) They have the same number of logical operators.
D) They both evaluate to true for at least one set of inputs.
Correct Answer: B
The definition of equivalent Boolean expressions is that they must produce the same result (true or false) for all possible combinations of input values, as stated in the provided content.
A) !p && !q
B) !p || !q
C) p || q
D) p && !q
Correct Answer: B
De Morgan's law states that the negation of a conjunction (&&) is the disjunction (||) of the negations. Therefore, `!(p && q)` is equivalent to `!p || !q`.
A) !x || !y
B) x && y
C) !x && !y
D) !x || y
Correct Answer: C
De Morgan's law states that the negation of a disjunction (||) is the conjunction (&&) of the negations. Therefore, `!(x || y)` is equivalent to `!x && !y`.
A) The contents or data stored within the objects.
B) Whether the objects are instances of the same class.
C) Whether the references point to the exact same object in memory.
D) The size of the objects in memory.
Correct Answer: C
The provided content states that object references can be compared using `==`. This operator checks for identity, not equality. It evaluates to true only if the two reference variables hold the same memory address, meaning they point to the identical object instance.
A) score >= 60 && !isLate
B) score > 60 || !isLate
C) score >= 60 || !isLate
D) score < 60 || isLate
Correct Answer: C
This requires applying De Morgan's law, where `!(a && b)` is equivalent to `!a || !b`. In this case, `a` is `score < 60` and `b` is `isLate`. The negation of `score < 60` is `score >= 60`. The negation of `isLate` is `!isLate`. Applying the law results in the equivalent expression `score >= 60 || !isLate`.
A) true
B) false
C) The value is indeterminate.
D) The code will not compile.
Correct Answer: A
The `new` keyword creates a new, distinct object in memory. Therefore, `obj1` and `obj2` are references to two separate objects. The `!=` operator compares the object references (their memory addresses), which are different. Thus, `obj1 != obj2` evaluates to `true`.
A) A compiler
B) De Morgan's law
C) A truth table
D) An object reference diagram
Correct Answer: C
The provided content explicitly states that 'Truth tables can be used to prove Boolean expressions are equivalent.' A truth table exhaustively checks every combination of input values to confirm the expressions produce the same output in all cases.
A) !a || b
B) a && !b
C) !a && b
D) !a && !b
Correct Answer: C
To find an equivalent expression, we apply De Morgan's law, where `!(x || y)` is equivalent to `!x && !y`. In this expression, `x` is `a` and `y` is `!b`. The law transforms `!(a || !b)` into `!a && !(!b)`. The double negation `!(!b)` simplifies to `b`, resulting in the final equivalent expression `!a && b`.
A) true
B) false
C) A
D) B
Correct Answer: A
Initially, `s1` and `s2` refer to two different String objects. The line `s2 = s1;` copies the reference (memory address) from `s1` into `s2`. After this assignment, both variables point to the exact same object. The `==` operator compares these references, finds them to be identical, and evaluates to `true`.
A) !(x && y)
B) !x || !y
C) !x && !y
D) An expression that is true unless both x and y are true.
Correct Answer: C
According to De Morgan's law, `!(x && y)` is equivalent to `!x || !y`. Option D is a textual description of the same logic. Option C, `!x && !y`, is equivalent to `!(x || y)` by the other form of De Morgan's law, and is therefore the one not equivalent to the others.
A) true
B) false
C) The code will cause a runtime error.
D) The code will not compile.
Correct Answer: A
The expression `(strA != strB)` evaluates to `true` because `strA` and `strB` are created as two separate objects with the `new` keyword, so their references are different. The expression `(strA == strC)` evaluates to `true` because `strC` is assigned the reference of `strA`, making them point to the same object. The overall expression becomes `true && true`, which evaluates to `true`.
A) a || b
B) !(a && b)
C) !b
D) !a || b
Correct Answer: D
Evaluating each option with `a = true` and `b = false`: A: `true || false` is `true`. B: `!(true && false)` is `!false`, which is `true`. C: `!false` is `true`. D: `!true || false` is `false || false`, which is `false`.
A) !isOnSale || !isOutOfStock
B) isOnSale && isOutOfStock
C) !isOnSale && !isOutOfStock
D) !isOnSale || isOutOfStock
Correct Answer: C
The initial condition is `isOnSale || isOutOfStock`. The requirement is to find the negation of this entire expression: `!(isOnSale || isOutOfStock)`. Applying De Morgan's law (`!(a || b)` is equivalent to `!a && !b`), we transform the expression into `!isOnSale && !isOutOfStock`.
A) obj1 != obj2
B) !obj1 == !obj2
C) obj1 && obj2
D) The expression cannot be simplified.
Correct Answer: A
The `!=` operator is defined as the logical opposite of the `==` operator for both primitive types and object references. Therefore, the expression `!(obj1 == obj2)` is always equivalent to `obj1 != obj2`. They both check if the two references point to different objects.