Skip to main content

AP Computer Science A Unit 1: Using Objects and Methods

Ready When You Are

Select a course and unit, then start practicing.

Students often underestimate Using Objects and Methods because it appears early in the syllabus, but AP questions here test application, not memorized definitions alone.

Fundamentals of Java, objects, methods, primitive types, and basic API usage. On the AP Computer Science A exam, items from Using Objects and Methods often ask you to apply course concepts to a scenario you have not memorized verbatim rather than recall isolated terms.

College Board topic statements for this unit include Primitive types (int, double, boolean) and expressions; Variables, assignment, evaluation order; Creating and using objects and calling methods; and String objects and common String methods.

On the AP Computer Science A exam, Using Objects and Methods is weighted at roughly 15%–25% of the multiple-choice section. That is enough to matter on score day even if your class spent only a few weeks here—especially when questions combine this unit with later material.

Time pressure makes Using Objects and Methods tempting to rush—especially when numbers or dates appear in every option. Slow down enough to identify what the question is actually asking before eliminating distractors.

Mix MCQ practice with sketching diagrams or timelines from memory. AP Computer Science A rewards recall under time pressure, not just recognition.

Alternate untimed review with mildly timed sets on Using Objects and Methods. Accuracy builds the foundation first; light time pressure later shows whether the ideas survived overnight.

Click Practice above for fresh MCQs tied to Using Objects and Methods. Answer, read the explanation, and log one sentence about why the correct choice works—that habit compounds faster than grinding endless worksheets.

Sample questions

A few exam-style multiple-choice questions from this unit, with answers and explanations.

  1. Question 1

    Consider the following Java code:

    double x = -2.5;
    long first = Math.round(x);
    x = x + 5.2;
    long second = Math.round(x);
    System.out.println(first + " " + second);

    What is printed?

    • A

      -3 2

    • B

      -2 2

    • C

      -2 3

      Correct answer
    • D

      -3 3

    Explanation

    Math.round(double) returns the nearest long; for a value exactly halfway between integers, it rounds toward positive infinity. Thus, Math.round(-2.5) is -2. The assignment then changes x to 2.7, so Math.round(2.7) is 3.

    D: Incorrect. It rounds the negative half value away from zero; Java rounds -2.5 to -2. B: Incorrect. It gets the first result right but treats 2.7 as if it rounded down to 2. C: Correct. The two calls return -2 and 3, respectively. A: Incorrect. It rounds -2.5 away from zero and rounds 2.7 down.

  2. Question 2

    A program calculates an approved amount and then caps it using an updated limit. What is printed?

    int limit = 23;
    double request = 17.5;
    double approved = Math.min(limit - 4, request + 2.0);
    limit = limit - 6;
    double finalAmount = Math.min(approved, limit);
    System.out.println(finalAmount);
    • A

      19.0

    • B

      13.0

    • C

      17.0

      Correct answer
    • D

      19.5

    Explanation

    First, limit - 4 is 1919 and request + 2.0 is 19.519.5, so the first Math.min call assigns 19.019.0 to approved. The assignment then changes limit to 1717. The second Math.min call compares 19.019.0 and 1717, producing the double value 17.017.0, which is printed.

    C. Correct: the updated limit is used in the second call, and the printed result is a double.

    A. Incorrect: 19.019.0 is the value of approved, but the second Math.min call reduces it to the updated limit.

    D. Incorrect: 19.519.5 is the larger value in the first comparison, not the value selected by Math.min.

    B. Incorrect: 1313 is not the updated value of limit; subtracting 66 from 2323 gives 1717.

  3. Question 3

    A program uses Math.random() to choose a ticket number and reports whether the number is greater than 33.

    double r = Math.random();
    int ticket = (int) (r * 5) + 1;
    boolean upper = ticket > 3;
    System.out.println(ticket + " " + upper);

    Which statement describes all possible output pairs?

    • A

      The ticket is from 11 through 55; upper is false for 11–33 and true for 44–55.

      Correct answer
    • B

      The ticket is from 11 through 55; upper is false for 11–22 and true for 33–55.

    • C

      The ticket is from 00 through 44; upper is false for 00–33 and true for 44.

    • D

      The ticket is from 11 through 66; upper is false for 11–33 and true for 44–66.

    Explanation

    Math.random() produces a value rr such that 0≤r<10 \le r < 1. Therefore, 0≤5r<50 \le 5r < 5, and casting the positive result to int gives a value from 00 through 44. Adding 11 makes ticket range from 11 through 55. The comparison ticket > 3 is true only for tickets 44 and 55.

    A is correct because it gives both the full ticket range and the corresponding boolean values. B is incorrect because the comparison is strictly greater than 33, so a ticket of 33 makes upper false. C is incorrect because the program adds 11 after casting, so the ticket cannot be 00. D is incorrect because rr is strictly less than 11, so the cast result cannot be 55 and the ticket cannot be 66.

  4. Question 4

    A program estimates the number of items available for an event and prints the target, estimate, and whether the estimate meets a minimum. What is printed?

    int trays = 5;
    double rate = 3.25;
    int target = Math.max(trays, 7);
    double estimate = Math.max(rate, target - trays) + 1.5;
    boolean enough = estimate >= 4.75;
    System.out.println(target + " " + estimate + " " + enough);
    • A

      7 4.75 false

    • B

      7 3.25 true

    • C

      7 4.75 true

      Correct answer
    • D

      7 3.5 false

    Explanation

    First, Math.max(trays, 7) returns 77, so target - trays is 22. In the next call, the integer 22 is converted to a double to match rate; Math.max(3.25, 2.0) returns 3.253.25. Adding 1.51.5 gives an estimate of 4.754.75, so enough is true. Because the first part of the printed expression is concatenated with a string, the values are printed as 7 4.75 true.

    C — Correct: the assignments and method calls produce the values shown.

    A — Incorrect: 4.75 >= 4.75 is true, not false.

    D — Incorrect: it treats the second Math.max call as though it selected the smaller argument.

    B — Incorrect: it omits the addition of 1.5 when calculating estimate.

  5. Question 5

    Consider the following Java code:

    String label = new String("sensor-A");
    int count = 3;
    double adjustment = 1.5;
    double score = count + adjustment * 2;
    count = count + 1;
    boolean qualifies = label.endsWith("-A") && score > count + 1.5;
    System.out.println(qualifies + " " + score);

    What is printed?

    • A

      true 5.0

    • B

      false 5.0

    • C

      false 6.0

    • D

      true 6.0

      Correct answer

    Explanation

    Multiplication is evaluated before addition, so score becomes 3+(1.5×2)=6.03 + (1.5 \times 2) = 6.0. After the assignment, count is 44. The String label ends with "-D", and 6.0>4+1.56.0 > 4 + 1.5, so qualifies is true. Concatenating the boolean, a space, and the double prints true 6.0.

    D. Correct: both the endsWith test and the numeric comparison are true. A. Incorrect: this would result from adding count and adjustment before multiplying, contrary to Java's arithmetic precedence. C. Incorrect: label.endsWith("-D") is true, and the numeric comparison is also true. B. Incorrect: it gives the wrong score and incorrectly makes the boolean false.

Frequently asked questions