AP® Computer Science A
Practice
AP® Computer Science A

AP® Computer Science A Unit 3 Cheat Sheet: Class Creation

Writing your own Java classes is the focus of this AP CSA Unit 3 cheat sheet: abstraction and class design, program impact, private instance variables, constructors, accessors and mutators, object references, static members, scope, and the this keyword. Unit 3 makes up 10% to 18% of the AP® Computer Science A exam. Choose Simple for the essentials or Ultimate for every rule and trap.

Practice AP® Computer Science A Unit 3 questions on Albert

What’s on the AP CSA Unit 3 Cheat Sheet?

Both versions follow Unit 3 of the College Board’s AP® Computer Science A course. Seven cards walk through topics 3.1 to 3.9 in order, and an eighth card is a playbook for free-response Question 2, Class Design, which tests this unit directly.

The Simple version gives you the core of class creation: how a spec turns into fields and methods, which members are public or private, how constructors work, the difference between void and non-void methods, what happens when you pass a primitive versus an object, how static variables are shared, a scope table, and the main uses of this.

The Ultimate version adds the details that decide close multiple-choice questions: private access between objects of the same class, constructor overloading and the missing default constructor, aliasing through mutable parameters, unreachable code after return, getters that leak private data, unique-ID and object-counter patterns with static variables, and a fuller FRQ 2 checklist. Start with Simple to learn the rules, then switch to Ultimate when you are tracing code under time pressure.

AP CSA Unit 3 at a Glance

TopicNameFocus
3.1Abstraction and Program DesignData and procedural abstraction, planning attributes and behaviors
3.2Impact of Program DesignSystem reliability, effects on society, intellectual property
3.3Anatomy of a Classpublic and private, instance variables, encapsulation
3.4ConstructorsSetting an object’s starting state
3.5Methods: How to Write ThemHeaders, return values, accessors and mutators
3.6Methods: Passing and Returning References of an ObjectWhat a method can and can’t change in the caller
3.7Class Variables and Methodsstatic fields, static methods, constants
3.8Scope and AccessLocal variables, parameters, shadowing
3.9this KeywordReferring to the current object

The AP CSA exam has 42 multiple-choice questions in 90 minutes (55% of the score) and four free-response questions in 90 minutes (45%). Unit 3 is 10% to 18% of the multiple-choice section, but its weight on the free-response section is larger than that number suggests: Question 2 asks you to write a complete class, and every other question hands you a class you have to read and use.

Key Concepts in Unit 3: Class Creation

Abstraction, Design, and Program Impact (3.1–3.2)

Abstraction reduces complexity by focusing on the main idea and hiding details the user doesn’t need. A class uses two kinds. Data abstraction lets you refer to data by name and properties without knowing how it is stored: code that uses a BankAccount knows the account has a balance, but never touches the field. Procedural abstraction gives a process a name, so callers know what deposit does without knowing how. Parameters make that method general, so one deposit(double amt) handles every amount.

Because callers depend only on a method’s name, parameters, and result, you can rewrite its body, for example to make it faster, without telling anyone, as long as the signature and purpose stay the same.

Worked example: A spec says “A Library has a name and a count of books on loan. A book can be checked out or returned.” The nouns become instance variables (String name, int onLoan). The verbs become methods (checkOut(), returnBook()). A rule such as “no library may lend more than 500 books” becomes a constant: public static final int MAX_LOANS = 500.

Topic 3.2 steps back from code. A reliable program does what it is supposed to under stated conditions, which is why you test with normal, boundary, and invalid inputs. Programs affect society, the economy, and culture, and even helpful ones can cause unintended harm. Reusing code raises intellectual property questions: open-source code comes with a license to follow, and other code needs permission, often a purchase.

Exam tip: Questions on 3.2 are conceptual. Read every option and pick the one that matches the definition, not the one that sounds most technical.

Anatomy of a Class and Encapsulation (3.3)

A class is a blueprint, and each object made with new gets its own copy of every instance variable. The standard layout is the class header, then private instance variables, then constructors, then methods. Classes and constructors are public. Instance variables are private, which is data encapsulation: outside code can only read or change an object’s data through its public methods, so the class can refuse bad values. A withdraw method can reject an amount larger than the balance, but nothing can stop acct.balance = -5 if balance is public.

Private access works per class, not per object. Inside BankAccount, a method can read other.balance when other is another BankAccount. Outside the class, the same expression is a compile error.

Worked example: If a Student class declares private double gpa, then in a separate Main class s.gpa does not compile, while s.getGpa() does.

Exam tip: On FRQ 2, declaring your instance variables private is worth a point. Leaving off private, or writing public, costs it.

Constructors (3.4)

A constructor has the same name as the class and no return type, not even void. It runs once each time new creates an object, and its job is to give every instance variable a starting value. Its parameters are local, so if you don’t copy them into fields they disappear when the constructor ends. If you write no constructor at all, Java supplies a no-argument one and every field gets its default value: 0, 0.0, false, or null. Once you write any constructor, that free default is gone.

Worked example: Given public Dog(String name, int age) { name = name; age = age; }, the object ends up with a null name and an age of 0. Each assignment sets a parameter to itself because the parameters shadow the fields. The fix is this.name = name; and this.age = age;.

Two more traps appear on multiple-choice questions. Adding void to a constructor header turns it into an ordinary method that new never calls. Writing int age = a; inside the constructor declares a new local variable instead of setting the field.

Exam tip: When a constructor receives a mutable object such as an array, storing it directly creates an alias. A copy keeps the caller from changing your object later.

Writing Methods (3.5)

A method header lists access, return type, name, and parameters. Accessors (getters) return a value without changing the object; mutators (setters) change a field and are usually void. A non-void method must reach a return statement with a value of the declared type on every path, and return ends the method immediately. A void method returns nothing, so its call can’t be used as a value. Returning a primitive returns a copy, so the caller changing that copy doesn’t change the field.

Worked example: public boolean withdraw(double amt) { if (amt > balance) { return false; } balance -= amt; return true; } With a balance of 40, withdraw(50) returns false and leaves the balance at 40. Then withdraw(15) returns true and leaves 25.

Exam tip: Read the return type in the spec first. “Returns true if” means boolean, and every branch of your code needs a return.

Passing and Returning Object References (3.6)

Java always passes arguments by value. For a primitive, the method gets a copy of the number. For an object, it gets a copy of the reference, so the parameter and the caller’s variable point to the same object. Calling a mutator through the parameter changes the caller’s object. Reassigning the parameter to a new object only changes the local variable.

Worked example: void m(Point p, int n) { p.setX(5); n = 5; p = new Point(); p.setX(7); } After m(a, k), a’s x is 5 and k is unchanged. The 7 went to a new object the caller never sees.

Returning an object works the same way: the caller gets a reference to the same object. A getter that returns a private array lets outside code change your private data.

Exam tip: Draw a box for each object and an arrow for each reference. A parameter is a new arrow to an existing box.

Static Variables, Scope, and this (3.7–3.9)

A static variable has one copy shared by every object of the class. A static method is called through the class name, as in Math.sqrt(x), and can’t use instance variables or this, because no particular object is involved. A static final variable is a constant. Scope decides where a variable exists: instance variables everywhere in the class, parameters within their method, and local variables from their declaration to the end of their block. A parameter with the same name as a field shadows it, and this.field reaches the field. You can also pass this as an argument to hand another object a reference to the current one.

Worked example: A class has private static int nextId = 1; and private int id;, and its constructor runs id = nextId; nextId++;. The first three objects get ids 1, 2, and 3, and nextId ends at 4.

Exam tip: Ask whether a value belongs to each object or to the whole class. That one question decides between an instance variable and a static one.

How Unit 3 Shows Up on the Exam

Multiple-choice questions give you a short class and ask what a code segment prints, which line causes a compile error, or which constructor or method header matches a call. Common setups include a parameter shadowing a field, a static counter shared across objects, a method that mutates or reassigns an object parameter, and outside code trying to reach a private field.

Free-response Question 2, Class Design, is worth 7 points. You get a description of a class and a table of example calls with their results, and you write the whole class: header, private instance variables, constructor, and the required methods. Scorers reward private instance variables of the right types, a constructor whose parameters match the example calls and that initializes every field, method headers with the exact names, parameters, and return types shown, and logic that produces the results in the table. The table often hides a field the description never names, such as a count of how many times a method has been called. If a method’s result depends on earlier calls, it needs a field to remember them.

Unit 3 skills show up in the other three free-response questions too, since each one gives you a class whose constructor and methods you must call correctly.

Common Mistakes in Unit 3

  • Writing name = name; in a constructor. The parameter is assigned to itself and the field never changes. Write this.name = name, or give the parameter a different name.
  • Declaring instance variables public. It breaks encapsulation and costs a point on FRQ 2. Make every instance variable private and add accessors where the spec needs them.
  • Printing instead of returning. If the spec says a method returns a value, System.out.println earns nothing. Return the value and let the caller print it.
  • Using an instance variable in a static method. A static method has no object to read from, so it doesn’t compile. Make the method an instance method or pass the object in.
  • Assuming a method can swap or replace the caller’s objects. Reassigning a parameter changes only the local copy of the reference. Only mutating the object through the reference reaches the caller.

Frequently Asked Questions

Can I use this cheat sheet on the AP CSA exam?

No. It’s a study tool for review before the exam. On exam day you get only the Java Quick Reference, which lists approved String, Math, ArrayList, and other library methods. It says nothing about how to write a class, so the rules on this sheet need to be in your head.

Should I start with the Simple or the Ultimate version?

Start the AP CSA Unit 3 cheat sheet with the Simple version if you are still learning what constructors, accessors, and static members do. Move to Ultimate once you can write a basic class from memory and want the edge cases that decide close multiple-choice questions and FRQ points.

Is inheritance part of Unit 3?

No. The current course framework places designing and implementing inheritance relationships outside the scope of the AP CSA course and exam. Unit 3 is about writing a single class well, and the AP CSA Unit 3 cheat sheet sticks to that scope.

How should I practice for FRQ 2?

Take a past Class Design question from AP Central, write the whole class in about 22 minutes without autocomplete or an IDE, and then check it against the scoring guidelines point by point. Pay closest attention to the example table, since it shows which fields you need.

Ready to practice? Try Albert free.

Build real confidence with thousands of adaptive practice questions across AP®, SAT®, ACT®, and core subjects — aligned to what you’re studying right now.

Practice for AP® Computer Science A