AP Computer Science A · Topic 1.2
Variables and Data Types Practice
Part of Primitive Types.
Practice questions
15
Sample questions
5 of 15 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 1/5
Which of the following is NOT a Java primitive type?
- A
boolean
- B
double
- C
int
- Dcheck_circle
String
Why
<code>String</code> is a class (reference type), not a primitive. AP CSA primitives: <code>int</code>, <code>double</code>, <code>boolean</code>.
- A
Sample 2difficulty 1/5
Which line correctly declares an integer variable named <code>count</code> initialized to 10?
- A
int count == 10;
- B
count int = 10;
- C
integer count = 10;
- Dcheck_circle
int count = 10;
Why
Java syntax: <code><type> <name> = <value>;</code> with a single <code>=</code> for assignment.
- A
Sample 3difficulty 1/5
A <code>boolean</code> variable in Java can hold
- A
Any int
- Bcheck_circle
true or false
- C
Any String
- D
0 or 1
Why
Java booleans are strictly <code>true</code> or <code>false</code>; not 0/1 like in some languages.
- A
Sample 4difficulty 2/5
boolean a = true; boolean b = false; System.out.println(a && !b);What is printed?
- Acheck_circle
true
- B
false
- C
0
- D
1
Why
!b is true, and true && true is true.
- A
Sample 5difficulty 2/5
Which is NOT a valid Java identifier?
- Acheck_circle
2nd
- B
myVar
- C
_count
- D
$total
Why
Identifiers cannot begin with a digit; can start with letter, <code>_</code>, or <code>$</code>.
- A