PrepGo

AP Computer Science A Practice Quiz: Boolean Expressions

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 9 questions to check your progress.

Question 1 of 9

Consider the following code snippet: int apples = 5; int oranges = 8; What is the result of the Boolean expression `apples < oranges`?

All Questions (9)

Consider the following code snippet: int apples = 5; int oranges = 8; What is the result of the Boolean expression `apples < oranges`?

A) true

B) false

C) 5

D) 8

Correct Answer: A

The relational operator `<` checks if the value on the left is less than the value on the right. Since 5 is less than 8, the expression evaluates to `true`.

Consider the following code snippet: double score = 90.0; int passingGrade = 90; What is the result of the Boolean expression `score >= passingGrade`?

A) true

B) false

C) 0.0

D) The code will produce a compilation error.

Correct Answer: A

The relational operator `>=` checks if the value on the left is greater than or equal to the value on the right. Since 90.0 is equal to 90, the expression evaluates to `true`.

What is the result of the following Boolean expression? `25 == (15 + 10)`

A) true

B) false

C) 25

D) The expression is invalid.

Correct Answer: A

The expression `(15 + 10)` is evaluated first, resulting in 25. The relational operator `==` then compares the primitive value 25 on the left with the primitive value 25 on the right. Since the values are the same, the expression evaluates to `true`.

Consider the following code snippet: int x = 10; int y = 10; boolean result = x != y; What value is stored in the variable `result` after this code is executed?

A) true

B) false

C) 10

D) The code will not compile.

Correct Answer: B

The relational operator `!=` checks if two values are not equal. Since the primitive values of `x` and `y` are both 10, they are equal. Therefore, the expression `x != y` evaluates to `false`, and this value is assigned to the `result` variable.

Consider the following code snippet: String str1 = new String("Java"); String str2 = new String("Java"); What is the result of the Boolean expression `str1 == str2`?

A) true

B) false

C) "Java"

D) The code will cause a runtime error.

Correct Answer: B

The `==` operator, when used with reference types like `String`, compares the object references (memory addresses), not the content of the objects. Since `str1` and `str2` are created as two distinct objects using the `new` keyword, they reside in different memory locations. Therefore, their references are not the same, and the expression evaluates to `false`.

Which of the following Boolean expressions evaluates to `false`? int a = 50; int b = 100; int c = 50;

A) a <= c

B) b > a

C) a == c

D) b <= a

Correct Answer: D

Let's evaluate each option: A) `50 <= 50` is true. B) `100 > 50` is true. C) `50 == 50` is true. D) `100 <= 50` is false, because 100 is not less than or equal to 50.

According to the provided content, how does the `==` operator function with primitive data types?

A) It compares the memory addresses where the values are stored.

B) It compares the actual primitive values.

C) It assigns the value from the right to the variable on the left.

D) It can only be used to compare integer values.

Correct Answer: B

The content explicitly states: 'With primitive types, this [==] compares the actual primitive values.' Comparing memory addresses is for reference types, and assignment is performed by the `=` operator.

Consider the following code snippet: String obj1 = "APCS"; String obj2 = obj1; What is the result of the Boolean expression `obj1 != obj2`?

A) true

B) false

C) APCS

D) The code will not compile.

Correct Answer: B

The `!=` operator checks if two object references are different. In the line `String obj2 = obj1;`, the reference (memory address) of `obj1` is copied to `obj2`. Both variables now point to the exact same object in memory. Therefore, the expression `obj1 != obj2` (are the references different?) evaluates to `false`.

Which statement best describes the use of relational operators like `<`, `>`, `<=`, and `>=` based on the provided content?

A) They can be used to compare any two values, including reference types.

B) They are used to determine the relationship between numeric values.

C) They are used exclusively to determine if two values are the same or different.

D) They result in a numeric value representing the difference between the operands.

Correct Answer: B

The content states: 'Numeric values can be compared using the relational operators <, >, <=, and >= to determine the relationship between the values.' This indicates their primary use is for comparing numeric types. They cannot be used to compare reference types (like Strings) in this manner.