Comparing Boolean Expressions MCQ Practice

Question 1 of 10

Which expression is equivalent to !(rain && cold) for every pair of boolean values?

  1. A. !rain && !cold
  2. B. !rain || !cold
  3. C. rain || cold
  4. D. rain && !cold

Question 2 of 10

A depot gate uses !(open || late). Which expression is equivalent for every pair of boolean values?

  1. A. !open || !late
  2. B. open && late
  3. C. !open && !late
  4. D. open || !late

Question 3 of 10

This truth table shows expression E. Which Java expression matches E for every row?

p q E
true true false
true false true
false true true
false false true
  1. A. p && q
  2. B. p || q
  3. C. !p || !q
  4. D. !p && !q

Question 4 of 10

Which expression is equivalent to a && (b || c) for every combination of boolean a, b, and c?

  1. A. (a && b) || (a && c)
  2. B. (a || b) && (a || c)
  3. C. a || (b && c)
  4. D. (a && b) && (a && c)

Question 5 of 10

A contest desk uses !(score >= 80 && late). Which expression is equivalent for every int score and boolean late?

  1. A. score < 80 && !late
  2. B. score < 80 || !late
  3. C. score > 80 || late
  4. D. score <= 80 && late

Question 6 of 10

Which pair of expressions is equivalent for every boolean x and y?

  1. A. !(x && y) and !x && !y
  2. B. !(x || y) and !x || !y
  3. C. !(x && y) and !x || !y
  4. D. x && y and !x || !y

Question 7 of 10

Two gate labels are constructed separately. What text does this Java code display?

String a = new String("gate");
String b = new String("gate");
System.out.print(a == b);
  1. A. true
  2. B. false
  3. C. gate
  4. D. The code throws a NullPointerException

Question 8 of 10

A row label is copied by assignment. What text does this Java code display?

String a = new String("row");
String b = a;
System.out.print(a == b);
  1. A. false
  2. B. true
  3. C. row
  4. D. The code throws a NullPointerException

Question 9 of 10

A kiosk reads an optional code. What text does this Java code display?

String code = null;
System.out.print(code != null && code.equals("OK"));
  1. A. false
  2. B. true
  3. C. The code throws a NullPointerException
  4. D. OK

Question 10 of 10

A Ticket stores a seat code. Ticket.equals returns true when both objects are non-null Tickets whose seat codes are equal according to String.equals.

Member Contract
Ticket(String seat) constructs a Ticket with the given seat code
equals true when the other object is a non-null Ticket with the same seat code

What text does this Java code display?

Ticket t1 = new Ticket("B4");
Ticket t2 = new Ticket("B4");
Ticket t3 = t1;
System.out.print((t1 == t2) + " " + t1.equals(t2) + " " + (t1 == t3));
  1. A. false true true
  2. B. true true true
  3. C. false false true
  4. D. false true false