• 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
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Unit 2 Boolean Expressions & Logic MCQ Practice

Home » AP CSA MCQ Practice » Unit 2: Selection and Iteration » Boolean Expressions & Logic

AP CSA Unit 2 Boolean Expressions & Logic MCQ Practice

📚 Topics 2.2, 2.5 & 2.6 ⏱️ 15 Min Practice ✅ Current AP CSA Framework

Boolean expressions are fundamental to selection and iteration in Java. In the current AP Computer Science A framework, this practice set covers Topic 2.2: Boolean Expressions, Topic 2.5: Compound Boolean Expressions, and Topic 2.6: Comparing Boolean Expressions.

Practice evaluating relational and logical operators, tracing compound Boolean expressions, applying De Morgan’s Laws, recognizing equivalent expressions, and understanding short-circuit evaluation. Work through the 12 questions below and review the explanation after each answer.

Quick Review: Expand the sections below for a step-by-step refresher before starting the quiz.

1. The Short-Circuit Evaluation Rule

Java evaluates logical expressions from left to right and can skip the remaining part of an expression when its result is already determined. This is called short-circuit evaluation.

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

Practice Tip: Short-circuit evaluation can prevent an expression on the right side from being evaluated. This is especially useful when the right side depends on a condition established by the left side.

2. De Morgan’s Laws

When a NOT operator (!) is applied to a compound Boolean expression, the logical operator changes and each condition is negated.

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

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

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

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

Boolean Expressions & Logic

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 && expression must be false. Java therefore skips the right side of the expression.

As a result, word.length() > 5 is never evaluated, and no NullPointerException occurs.
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:

1. Negate x > 10 → x <= 10
2. Change || to &&
3. Negate y <= 5 → y > 5

Therefore:!(x > 10 || y <= 5)is equivalent to:x <= 10 && y > 5.
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. !(true) → false
4. true && false → false

Therefore, result is 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 The expression is true in exactly two cases:

1. p is true and q is false: p && !q
2. p is false and q is true: !p && q

The || combines these two cases.
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 this is an AND expression, Java short-circuits and does not call check(a).

In the else if, a < 10 is true. Because this is an OR expression, Java again short-circuits and does not call check(a).

Therefore, only PathB is printed.
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 Both conditions must be true before the return true statement is reached.

Therefore, the equivalent Boolean expression is:(score >= 90) && (att >= 95).
7. Assume A and B are Boolean variables. Which of the following expressions is always logically equivalent to (A && B) || A?
Correct Answer: A Consider the two possible values of A.

If A is true:(true && B) || trueis true regardless of B.

If A is false:(false && B) || falseis false.

Therefore, the entire expression always has the same value as A.
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 value cannot be greater than 5 and less than or equal to 5 at the same time. These conditions are mutually exclusive, and they are connected with &&, so the expression always evaluates to 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 Apply De Morgan’s Laws:

1. Negate str.equals("quit") → !str.equals("quit")
2. Change || to &&
3. Negate str.length() < 3 → str.length() >= 3

Therefore, the equivalent expression is:!str.equals("quit") && str.length() >= 3.
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 each part:

1. (p || q) → (false || true) → true
2. (q || r) → (true || false) → true
3. !(p && r) → !(false && false) → true

Therefore:true && true && trueevaluates to 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 Evaluate the arithmetic and comparison expressions first:

5 + 3 > 7 → 8 > 7 → true
4 * 2 == 8 → 8 == 8 → true
!true → false

The expression becomes:true && true || false

The AND operation evaluates to true, and then:true || false → 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 two new String("Java") expressions create two distinct String objects, so the references are different.

s1.equals(s2) evaluates to true because the two String objects contain the same sequence of characters.

Therefore:false || true → true.

Boolean Expressions Practice Complete!

0 / 12

Why Boolean Logic Matters for AP CSA

Boolean expressions are used throughout Java selection and iteration. Understanding relational operators, logical operators, compound conditions, and equivalent Boolean expressions helps you trace code and determine how conditional statements and loops behave.

The concepts practiced here are especially useful as you move from Boolean expressions into if statements and loops in Unit 2. Pay close attention to how &&, ||, and ! affect the evaluation of compound expressions.

Continue Your AP CSA Practice

You have completed the Boolean Expressions & Logic practice set covering Topics 2.2, 2.5, and 2.6. Continue with the next available Unit 2 practice page on while loops.

← Back to Unit 2: Selection & Iteration

← Back to AP CSA MCQ Practice Hub
Next: While Loops →

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: Examples, Types & Constructor Overloading
  • 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