• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Booleans
      • Iteration
      • Arrays
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Truth Tables & Boolean Logic MCQs | JavaTutorOnline

Home » AP CSA MCQ » Unit 3: Truth Tables

AP CSA Practice: Truth Tables & Booleans

📚 Unit 3 Logic ⏱️ 15 Min Practice ✅ Exam Readiness

Boolean logic forms the backbone of all control flow in Java. On the AP CSA exam, questions testing your knowledge of if statements, logical operators (&&, ||, !), and Truth Tables account for up to 17.5% of your multiple-choice score.

In this module, you will practice tracing complex compound expressions, simplifying logic using De Morgan’s Laws, and identifying hidden NullPointerExceptions. Work through the 12 questions below to master Unit 3.

Crash Course: Expand the sections below for a quick step-by-step refresher before starting the quiz.

1. The Short-Circuit Evaluation Rule

Java optimizes logical expressions by skipping unnecessary evaluations. This is called short-circuiting.

  • AND (&&): If the left side is false, the entire expression must be false. Java skips the right side entirely.
  • OR (||): If the left side is true, the entire expression must be true. Java skips the right side entirely.

Exam Trap: The College Board loves to put code that would throw a runtime error on the right side of a short-circuited expression. If it gets skipped, the program survives!

2. De Morgan’s Laws

When you distribute a NOT operator (!) across a compound expression, three things must happen:

  1. Negate the first condition.
  2. Negate the second condition.
  3. Flip the logical operator (&& becomes ||, and vice versa).

Example: Simplify !(x > 5 && y == 10)

  • x > 5 becomes x <= 5
  • && becomes ||
  • y == 10 becomes y != 10

Result: x <= 5 || y != 10

Truth Tables & Booleans

Question 1 of 12 | Score: 0
1. Consider the following code segment:
String word = null;
boolean isValid = (word != null) && (word.length() > 5);
System.out.println(isValid);
What is printed as a result of executing the code segment?
Correct Answer: B This question tests short-circuit evaluation. Because word != null evaluates to false, the entire && statement is guaranteed to be false. Java optimizes this by short-circuiting (skipping) the right side. Therefore, word.length() > 5 is never executed, and the NullPointerException is avoided.
2. Which of the following boolean expressions is logically equivalent to the expression below?
!(x > 10 || y <= 5)
Correct Answer: B Applying De Morgan’s Laws requires three steps:
1. Negate (x > 10) → (x <= 10)
2. Flip the OR (||) to an AND (&&)
3. Negate (y <= 5) → (y > 5).
The opposite of “greater than” is “less than OR equal to.”
3. Assume a, b, and c are initialized boolean variables. If a = true, b = false, and c = true, what is the value of result?
boolean result = (a || b) && !(c && a);
Correct Answer: B Substitute the values:
1. (true || false) → true.
2. (true && true) → true.
3. Apply the NOT operator to the second half: !(true) → false.
4. Combine them: true && false results in false.
4. Assume p and q are boolean variables. Which of the following expressions evaluates to true if and only if exactly one of the variables is true?
Correct Answer: C This represents “Exclusive OR” (XOR) logic. The expression checks for the two valid scenarios where exactly one variable is true:
1: p is true AND q is false (p && !q)
2: p is false AND q is true (!p && q).
If either scenario is true, the OR ensures the statement returns true.
5. Consider the following code segment:
public static boolean check(int n) {
System.out.print(“Check “);
return n % 2 == 0;
}
public static void main(String[] args) {
int a = 5;
if (a > 10 && check(a)) {
System.out.print(“PathA”);
} else if (a < 10 || check(a)) {
System.out.print(“PathB”);
}
}
What is printed when this code is executed?
Correct Answer: D In the first if, a > 10 is false. Because it’s an AND statement, Java short-circuits and skips the check(a) method. In the else if, a < 10 is true. Because it is an OR statement, Java short-circuits again, skipping the second check(a) call. Since the method is never executed, “Check” is never printed. Only “PathB” prints.
6. Which of the following boolean expressions is logically equivalent to the nested conditional structure below?
if (score >= 90) {
if (att >= 95) {
return true;
}
}
return false;
Correct Answer: B A nested if statement requires both the outer condition AND the inner condition to be true in order to execute the innermost block. This is the exact definition of the logical AND (&&) operator.
7. Assume A and B are boolean variables. Which of the following expressions is always logically equivalent to (A && B) || A?
Correct Answer: A This is a logic simplification based on the Absorption Law.
If A is true: (true && B) || true evaluates to true regardless of B.
If A is false: (false && B) || false evaluates to false.
Since the final result always matches the value of A, variable B is irrelevant.
8. Assume x is an initialized integer variable. Which of the following expressions will always evaluate to false regardless of the value of x?
Correct Answer: D A number cannot simultaneously be greater than 5 AND less than or equal to 5. Because these are mutually exclusive conditions joined by an AND operator, the statement is a logical contradiction and will always be false.
9. Consider the following boolean expression involving a String object named str:
!(str.equals(“quit”) || str.length() < 3)
Which of the following is logically equivalent to the expression above?
Correct Answer: B Applying De Morgan’s Laws requires three steps:
1. Negate the first condition: str.equals("quit") becomes !str.equals("quit").
2. Flip the OR (||) to an AND (&&).
3. Negate the second condition: < (strictly less than) becomes >= (greater than or equal to).
10. Assume the following variables have been declared and initialized:
boolean p = false;
boolean q = true;
boolean r = false;
What does the expression (p || q) && (q || r) && !(p && r) evaluate to?
Correct Answer: A Evaluate step-by-step:
1. (p || q) → (false || true) → true
2. (q || r) → (true || false) → true
3. !(p && r) → !(false && false) → true
Combine them all: true && true && true yields true.
11. Consider the following boolean assignment. What is the final value of result?
boolean result = 5 + 3 > 7 && 4 * 2 == 8 || !true;
Correct Answer: A This tests Java’s operator precedence: Arithmetic, Relational, Equality, NOT (!), AND (&&), OR (||).
1. Arithmetic: 8 > 7 && 8 == 8 || !true
2. Relational & Equality: true && true || !true
3. Logical NOT: true && true || false
4. Logical AND: true || false
5. Logical OR: true
12. Consider the following code segment. What is the value of result?
String s1 = new String(“Java”);
String s2 = new String(“Java”);
boolean result = (s1 == s2) || s1.equals(s2);
Correct Answer: A • s1 == s2 evaluates to false because the new keyword creates two distinct objects in memory, so their memory addresses do not match.
• s1.equals(s2) evaluates to true because the .equals() method compares the actual character contents.
The expression becomes false || true, which evaluates to true.

Truth Tables Practice Complete!

0 / 12

Why Boolean Logic Matters for AP CSA

While unit 3 focuses heavily on if/else statements, the logic you just practiced is the exact same logic required for Unit 4: Iteration. Every single while loop and for loop relies on a boolean expression to determine if the loop should continue executing or terminate.

If you do not fully understand how && and || interact, you will inevitably write code that results in infinite loops or skips essential array elements. Keep practicing De Morgan’s Laws until flipping the operators becomes second nature.

Ready for the Next Step?

Now that you have mastered control flow boundaries and condition evaluation, it is time to start repeating execution blocks using Iteration.

Continue your AP CSA review by heading over to the core arrays module or diving into standard looping algorithms.

← Back to MCQ Practice Hub
Next: Unit 6 Array Creation →

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java and Overloaded Constructor Example Program
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline