Boolean Expressions MCQ Practice

Question 1 of 10

A pantry tracks unused jars. What text does this Java code display?

int jars = 9;
System.out.print(jars == 4);
  1. A. false
  2. B. true
  3. C. 9
  4. D. 4

Question 2 of 10

A shuttle logs remaining fuel units. What text does this Java code display?

int fuel = 40;
System.out.print(fuel != 17);
  1. A. 17
  2. B. false
  3. C. 40
  4. D. true

Question 3 of 10

A warehouse restacks cartons. What text does this Java code display?

int cartons = 6;
System.out.print(cartons <= 6);
System.out.print(cartons < 6);
  1. A. falsetrue
  2. B. truetrue
  3. C. truefalse
  4. D. falsefalse

Question 4 of 10

Beads are grouped by 7. What text does this Java code display?

int beads = 26;
System.out.print(beads / 7 == 3);
System.out.print(beads / 7 > 3);
  1. A. truefalse
  2. B. falsetrue
  3. C. truetrue
  4. D. falsefalse

Question 5 of 10

A scale stores a double reading. What text does this Java code display?

int whole = 9;
double mix = 9.0;
System.out.print(whole / 2 > 4);
System.out.print(mix / 2 > 4);
  1. A. truetrue
  2. B. falsefalse
  3. C. truefalse
  4. D. falsetrue

Question 6 of 10

Two badge objects are constructed. What text does this Java code display?

class Badge {
}
Badge first = new Badge();
Badge second = new Badge();
Badge copy = first;
System.out.print(first == second);
System.out.print(first == copy);
System.out.print(second != copy);
  1. A. falsetruetrue
  2. B. truetruetrue
  3. C. falsefalsetrue
  4. D. falsetruefalse

Question 7 of 10

A trail marker is stored as char. What text does this Java code display?

char mark = 'C';
System.out.print(mark == 'C');
System.out.print(mark < 'A');
  1. A. truetrue
  2. B. falsefalse
  3. C. falsetrue
  4. D. truefalse

Question 8 of 10

String tags are compared. Which expression is valid Java and tests whether the two variables refer to the same object?

String a = new String("hi");
String b = new String("hi");
  1. A. a < b
  2. B. a >= b
  3. C. a == b
  4. D. a > b

Question 9 of 10

A missing label is represented by null. What text does this Java code display?

String tag = null;
String other = new String("gate");
System.out.print(tag == null);
System.out.print(other == null);
  1. A. falsefalse
  2. B. truefalse
  3. C. falsetrue
  4. D. truetrue

Question 10 of 10

An int counter wraps past its minimum value. What text does this Java code display?

int depth = -2147483648;
depth = depth - 1;
System.out.print(depth < 0);
  1. A. true
  2. B. false
  3. C. -2147483649
  4. D. -1