AP CSA Unit 3 Practice Exam: Class Creation (Part 2)

Unit 3: Class Creation

Part 2: Questions 26-50

Methods • Static vs Instance • Scope • toString & equals • Class Design

New AP CSA Curriculum (2025-2026): Part 2 of the Unit 3 practice exam covers methods, static vs instance members, scope and parameter passing, the this keyword, toString/equals, and has-a class design.
0 Correct | 0 Incorrect | 0/25 Answered
Methods (Questions 26-31)
Question 26

Consider the following class. Which of the following are valid accessor (getter) methods? Select the correct combination.

public class Inventory { private int stock; private String label; // I. public int getStock() { return stock; } // II. public void getLabel() { System.out.println(label); } // III. public String getLabel() { return label; } }
Question 27

What is printed?

public class Q { private int v; public Q(int x) { v = x; } public int adjust(int x) { v = v + x; return v - x; } } // In main: Q obj = new Q(10); int r1 = obj.adjust(3); int r2 = obj.adjust(2); System.out.println(r1 + " " + r2);
Question 28

Identify what is wrong with the mutator method below.

public class Account { private double balance; public double setBalance(double newBalance) { if (newBalance >= 0) { balance = newBalance; } } }
Question 29

Consider the following methods. Which call(s) will compile?

public class Helper { public int run(int a, int b) { return a + b; } public double run(double a, double b) { return a + b; } public int run(int a) { return a * 2; } } // In main: Helper h = new Helper(); // I. h.run(5, 3); // II. h.run(5); // III. h.run(5.0, 3);
Question 30

A method header is shown. Which call(s) will NOT compile?

public void process(String s, int n) { /* ... */ } // I. process("hello", 5); // II. process(5, "hello"); // III. process("hello");
Question 31

What is printed?

public class M { public int compute(int x) { if (x < 5) return x * 2; x = x - 1; return compute(x); } } // In main: M m = new M(); System.out.println(m.compute(7));
Static vs Instance (Questions 32-37)
Question 32

What is printed?

public class Tag { private static int total = 0; private int id; public Tag() { total++; id = total; } public static int getTotal() { return total; } public int getId() { return id; } } // In main: Tag a = new Tag(); Tag b = new Tag(); Tag c = new Tag(); System.out.println(a.getId() + " " + b.getId() + " " + Tag.getTotal());
Question 33

Consider the following class. Which of the following statements about the method show() is FALSE?

public class Widget { private int count; private static String tag = "W"; public static void show() { // body here } }
Question 34

Which line(s) cause a compile error?

public class Item { public static int total = 0; public int qty; public Item(int q) { qty = q; total += q; } } // In main (different class): Item a = new Item(5); int x = Item.total; // Line I int y = a.total; // Line II int z = Item.qty; // Line III
Question 35

Consider the following class. What is printed?

public class Counter { private static int shared = 0; private int local = 0; public void bump() { shared++; local++; } public String report() { return shared + "," + local; } } // In main: Counter x = new Counter(); Counter y = new Counter(); x.bump(); x.bump(); x.bump(); y.bump(); System.out.println(x.report()); System.out.println(y.report());
Question 36

Which statement about static methods is TRUE?

Question 37

What is printed?

public class Track { private static int count; private int n; public Track() { n = ++count; } public int getN() { return n; } public static int getCount() { return count; } } // In main: Track[] arr = new Track[3]; for (int i = 0; i < arr.length; i++) { arr[i] = new Track(); } System.out.println(arr[0].getN() + " " + Track.getCount());
Scope, this, and Parameter Passing (Questions 38-43)
Question 38

What is printed?

public class S { private int n = 100; public void update(int n) { n = n + 1; System.out.println(n + " " + this.n); } } // In main: S s = new S(); s.update(5);
Question 39

What is printed? (Pay attention to parameter passing.)

public class Test { public void modify(int x) { x = x * 2; } public void modify(int[] arr) { arr[0] = arr[0] * 2; } } // In main: Test t = new Test(); int num = 5; int[] data = {5}; t.modify(num); t.modify(data); System.out.println(num + " " + data[0]);
Question 40

Which line(s) below would cause a compile error?

public class Sample { private int v; public Sample(int v) { v = v; // Line I this.v = v; // Line II this(0); // Line III } }
Question 41

What is printed?

public class Sw { public int q; public Sw(int q) { this.q = q; } public Sw merge(Sw other) { this.q = this.q + other.q; return this; } } // In main: Sw a = new Sw(2); Sw b = new Sw(3); Sw c = a.merge(b).merge(b); System.out.println(a.q + " " + b.q + " " + c.q);
Question 42

Consider the following code. What is the value of the local variable returned at the marked line?

public class Scope { private int v = 10; public int test() { int v = 5; if (v > 0) { int v2 = v + 1; v = v2; } return v; // Marked line } }
Question 43

Which statement about this is FALSE?

toString and equals (Questions 44-47)
Question 44

What is printed?

public class P { private int x, y; public P(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "@" + y; } } // In main: P p = new P(3, 4); System.out.println(p); System.out.println("Loc: " + p);
Question 45

Consider the class. What is printed?

public class Box { private int side; public Box(int s) { side = s; } } // In main: Box b1 = new Box(5); Box b2 = new Box(5); Box b3 = b1; System.out.println(b1 == b2); System.out.println(b1 == b3); System.out.println(b1.equals(b2));
Question 46

Examine the equals method below. Which of the following correctly identifies its problem?

public class Card { private int rank; private String suit; public boolean equals(Card other) { return this.rank == other.rank && this.suit.equals(other.suit); } }
Question 47

What is printed?

public class Tag { private String label; public Tag(String s) { label = s; } public boolean equals(Object o) { if (!(o instanceof Tag)) return false; Tag t = (Tag) o; return this.label.equals(t.label); } } // In main: Tag t1 = new Tag("AP"); Tag t2 = new Tag("AP"); String s = "AP"; System.out.println(t1.equals(t2)); System.out.println(t1.equals(s)); System.out.println(t1 == t2);
Class Design and has-a Relationships (Questions 48-50)
Question 48

A program needs to model a Library that contains many Books. Each Book has a title and author. Which class structure best represents this relationship?

Question 49

Consider the following design. What is the most significant problem?

public class Order { public String customerName; public double total; public String status; public Order(String n, double t) { customerName = n; total = t; status = "pending"; } }
Question 50

A program models a Car that has an Engine. Which of the following are valid implementations of this has-a relationship? Select the correct combination.

// I. public class Car { private Engine engine; public Car() { engine = new Engine(); } } // II. public class Car extends Engine { } // III. public class Car { private Engine engine; public Car(Engine e) { engine = e; } }

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]