Compound Boolean Expressions MCQ Practice

Question 1 of 10

A lake dock opens only when both conditions are true. What text does this Java code display?

boolean calm = true;
boolean staffed = false;
System.out.print(calm && staffed);
  1. A. true
  2. B. false
  3. C. calm
  4. D. 0

Question 2 of 10

A shuttle boards if the rider is late or a standby seat exists. What text does this Java code display?

boolean late = false;
boolean standby = true;
System.out.print(late || standby);
  1. A. false
  2. B. true
  3. C. late
  4. D. 1

Question 3 of 10

A locker prints a compound check. ! is applied before &&. What text does this Java code display?

boolean locked = false;
boolean keyed = false;
System.out.print(!locked && keyed);
  1. A. true
  2. B. false
  3. C. locked
  4. D. The code does not compile

Question 4 of 10

Java evaluates && before ||. What text does this Java code display?

boolean a = true;
boolean b = false;
boolean c = false;
System.out.print(a || b && c);
  1. A. true
  2. B. false
  3. C. 0
  4. D. The code throws an exception

Question 5 of 10

A trail sign uses !, &&, and || together. What text does this Java code display?

boolean wet = false;
boolean cold = true;
boolean windy = false;
System.out.print(!wet || cold && windy);
  1. A. true
  2. B. false
  3. C. wet
  4. D. The code does not compile

Question 6 of 10

A ferry estimates riders per open ramp. What text does this Java code display?

int ramps = 0;
int riders = 18;
boolean packed = (ramps > 0) && (riders / ramps > 4);
System.out.print(packed);
  1. A. false
  2. B. true
  3. C. The code throws an ArithmeticException
  4. D. 4

Question 7 of 10

The method ping prints P when it runs. What text does this Java code display?

public boolean ping()
{
    System.out.print("P");
    return false;
}

boolean online = true;
System.out.print(online || ping());
  1. A. true
  2. B. Ptrue
  3. C. Pfalse
  4. D. false

Question 8 of 10

A greenhouse heater uses relational tests inside a compound boolean. What text does this Java code display?

int temp = 4;
boolean frost = temp < 5 && temp != 0 || temp > 20;
System.out.print(frost);
  1. A. true
  2. B. false
  3. C. 4
  4. D. The code does not compile

Question 9 of 10

The method stamp prints S when it runs. What text does this Java code display?

public boolean stamp()
{
    System.out.print("S");
    return true;
}

boolean dry = false;
System.out.print(dry && stamp());
  1. A. false
  2. B. Strue
  3. C. Sfalse
  4. D. true

Question 10 of 10

The method trip prints T when it runs. && is evaluated before ||. What text does this Java code display?

public boolean trip()
{
    System.out.print("T");
    return true;
}

boolean alarm = false;
int gap = 0;
System.out.print(alarm && trip() || (gap > 0) && (10 / gap == 2));
  1. A. false
  2. B. Tfalse
  3. C. Ttrue
  4. D. The code throws an ArithmeticException