Comparing Boolean Expressions MCQ Practice

Question 1 of 10

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

  1. A. !full && !closed
  2. B. full || closed
  3. C. !full || !closed
  4. D. full && !closed

Question 2 of 10

A ferry holds if !(night || fog). Which expression is equivalent for every pair of boolean values?

  1. A. !night || !fog
  2. B. !night && !fog
  3. C. night && fog
  4. D. night || !fog

Question 3 of 10

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

p q F
true true false
true false false
false true false
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 !(x < 3 || y >= 10) for every int x and y?

  1. A. x >= 3 && y < 10
  2. B. x > 3 && y < 10
  3. C. x >= 3 || y < 10
  4. D. x < 3 && y >= 10

Question 5 of 10

Which expression is equivalent to !a || !b for every boolean a and b?

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

Question 6 of 10

Which expression is equivalent to !(!p && q) for every boolean p and q?

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

Question 7 of 10

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

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

Question 8 of 10

A harbor printer shows both a reference test and a content test. What text does this Java code display?

String m = new String("dock");
String n = new String("dock");
System.out.print((m == n) + ":" + m.equals(n));
  1. A. true:true
  2. B. false:false
  3. C. false:true
  4. D. true:false

Question 9 of 10

Two optional labels are compared with ==. What text does this Java code display?

String left = null;
String right = null;
System.out.print(left == right);
  1. A. true
  2. B. false
  3. C. The code throws a NullPointerException
  4. D. null

Question 10 of 10

A Badge stores an id string. Badge.equals returns true when both objects are non-null Badges whose id strings are equal according to String.equals.

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

What text does this Java code display?

Badge a = new Badge("K9");
Badge b = new Badge("K9");
Badge c = null;
System.out.print(a.equals(b) + " " + (a == b) + " " + (c == null));
  1. A. true false true
  2. B. true true true
  3. C. false false true
  4. D. true false false