AP Computer Science A · Topic 1.2

Variables and Data Types Practice

Part of Primitive Types.

Practice questions

15

Want a predicted score for the whole AP CSA exam? Take the 20-question diagnostic and Lumi will plan the rest.

Sample questions

5 of 15 — sign in to practice the rest with adaptive difficulty and mastery tracking.

  1. Sample 1difficulty 1/5

    Which of the following is NOT a Java primitive type?

    • A

      boolean

    • B

      double

    • C

      int

    • D

      String

      check_circle

    Why

    <code>String</code> is a class (reference type), not a primitive. AP CSA primitives: <code>int</code>, <code>double</code>, <code>boolean</code>.

  2. 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;

    • D

      int count = 10;

      check_circle

    Why

    Java syntax: <code><type> <name> = <value>;</code> with a single <code>=</code> for assignment.

  3. Sample 3difficulty 1/5

    A <code>boolean</code> variable in Java can hold

    • A

      Any int

    • B

      true or false

      check_circle
    • 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.

  4. Sample 4difficulty 2/5

    boolean a = true;
    boolean b = false;
    System.out.println(a && !b);

    What is printed?

    • A

      true

      check_circle
    • B

      false

    • C

      0

    • D

      1

    Why

    !b is true, and true && true is true.

  5. Sample 5difficulty 2/5

    Which is NOT a valid Java identifier?

    • A

      2nd

      check_circle
    • B

      myVar

    • C

      _count

    • D

      $total

    Why

    Identifiers cannot begin with a digit; can start with letter, <code>_</code>, or <code>$</code>.