AP CSA Unit 1.4: Assignment Statements and Value Copying Practice

Unit 1, Section 1.4
Day 4 Practice • January 10, 2026
🎯 Focus: Assignment Statements and Value Copying

Practice Question

Consider the following code segment:
int x = 5;
int y = x;
x = 10;
System.out.println(x + " " + y);
What is printed as a result of executing this code segment?

What This Tests: Section 1.4 covers assignment statements. This question tests understanding that primitive variables store values independently—assigning y = x copies the current value of x (5) into y. Changing x later doesn't affect y.

Key Concept: Value Copying with Primitives

When you assign one primitive variable to another, the value is copied. The variables remain independent—changing one doesn't affect the other.

int x = 5;    // x has its own copy: 5
int y = x;    // y gets a COPY of x's value: 5
x = 10;       // Only x changes to 10
              // y still has its own copy: 5

Step-by-Step Trace

Line Code x y
1 int x = 5; 5 -
2 int y = x; 5 5 (copied from x)
3 x = 10; 10 5 (unchanged)
4 println(x + " " + y); 10 5

Output: 10 5

Common Mistakes

Mistake: Answer B (10 10)

This assumes y is "linked" to x and updates when x changes. But primitives copy values—y got a copy of 5 and keeps it regardless of what happens to x.

Mistake: Answer A (5 5)

This forgets that x was reassigned to 10 on line 3. Always trace each line in order!

Primitives vs Objects

Important Distinction

Primitives (int, double, boolean): Assignment copies the value. Variables are independent.

Objects: Assignment copies the reference (address). Both variables point to the same object. (Covered in Unit 3)

Related Topics

  • Section 1.2: Variables and Data Types
  • Section 1.6: Compound Assignment Operators
  • Section 3.6: Passing Object References
Difficulty: Medium • Time: 2 minutes • AP Skill: 1.B - Determine code behavior

Ready to Level Up Your AP CSA Skills?

Get personalized help or access our complete question bank

Premium Question Bank - Coming Soon! Schedule 1-on-1 Tutoring

300+ Unit 1 questions • Expert tutoring • 5.0 rating

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.