Abstraction and Program Design
Data abstraction names a type without exposing storage details. Procedural abstraction names a process through a method. Use both to design a class by listing attributes and behaviors before writing code.
Unit 3 is about creating Java classes. You declare private instance variables, write public constructors to initialize them, and define methods that expose or modify object state. You also learn when to use static members, how scope determines which variable a name refers to, and how this references the current object.
Fiveable's AP Computer Science A Unit 3 review covers 9 topics, with guided practice questions for the unit.
Data abstraction names a type without exposing storage details. Procedural abstraction names a process through a method. Use both to design a class by listing attributes and behaviors before writing code.
Programs affect society, the economy, and culture. Maximize reliability through testing, recognize unintended harms, and follow open-source and intellectual property rules when reusing code.
A Java class has a public class header, private instance variables, and public constructors and methods. The keywords public and private control access and enforce encapsulation.
A constructor initializes all instance variables when an object is created with new. If no constructor is provided, Java supplies default values. Copy mutable parameters to prevent aliasing.
Void methods perform actions without returning a value. Non-void methods return a single value by value. Accessor methods read state; mutator methods update it. Primitives passed to methods are copied, so the original never changes.
Passing an object copies the reference, not the object. The method can modify the original object through that shared reference. Returning an object reference exposes the original, not a new copy.
Static variables are shared by all objects of a class. Static methods belong to the class and cannot access instance variables without receiving an object parameter. Use final to declare constants.
Local variables and parameters exist only in their declaring block. When a local name matches an instance variable name, the local name wins inside that block. Use this to reach the instance variable.
this refers to the current object inside any instance method or constructor. Use this.field to resolve shadowing, and pass this as an argument to give another method access to the current object. Static methods have no this.
Try AP-style questions on unit 3, then use the review notes below for anything you miss.
A timed, AP-style test built only from unit 3 questions — multiple choice plus free response, scored with AI feedback. Use the standard format or build your own.
Abstraction reduces complexity by focusing on the main idea and hiding irrelevant details. Before writing code, you can design a class by listing its attributes (data it stores) and behaviors (actions it can perform). UML class diagrams and natural-language descriptions are both valid design tools on the AP exam.
Can you list the attributes and behaviors for a class like BankAccount or Student before writing any Java code?
| Abstraction type | What it names | What it hides |
|---|---|---|
| Data abstraction | A variable or data type | How the data is stored in memory |
| Procedural abstraction | A method or process | The implementation steps inside the method |
Writing a class is not just a technical act. Programs affect society, the economy, and culture in both intended and unintended ways. Reliability and legal compliance are responsibilities every programmer carries.
What is the difference between open-source code and proprietary code in terms of what a programmer is allowed to do with it?
| Code type | Permission needed? | Cost possible? |
|---|---|---|
| Open source | No | No |
| Proprietary / not open source | Yes | Often yes |
A Java class has a public class header, private instance variables, and public constructors. The constructor sets the initial state of an object by assigning values to every instance variable. When new is called, memory is allocated and a reference to the new object is returned.
Write the constructor header and instance variable declarations for a class called Movie with a String title and an int year.
| Member | Access modifier | Purpose |
|---|---|---|
| Instance variable | private | Stores per-object state |
| Constructor | public | Initializes instance variables when object is created |
| Accessor method | public | Returns a copy of an instance variable's value |
| Mutator method | public | Updates an instance variable's value |
Methods define what objects can do. Void methods perform actions without returning a value. Non-void methods evaluate a return expression and hand back a single value. Primitives are passed by value, so the original argument never changes. Object references are also passed by value, but because the parameter holds a copy of the reference, the method can still modify the original object's state through that shared reference.
If a method receives an int parameter and doubles it, does the original int variable in the caller change? What if the parameter is an ArrayList?
| Parameter type | What is copied | Can method change original? |
|---|---|---|
| Primitive (int, double, boolean) | The value itself | No |
| Object reference | The reference (memory address) | Yes, through the shared reference |
Static members belong to the class itself, not to any individual object. A static variable has one shared copy across all objects. A static method runs without a specific object instance and cannot access instance variables or call instance methods unless an object is passed in as a parameter.
Why can a static method not call an instance method directly, and how would you work around that restriction?
| Member type | Keyword | One copy per | Can access instance variables? |
|---|---|---|---|
| Instance variable | (none) | Object | Yes |
| Class variable | static | Class | No (it is one itself) |
| Instance method | (none) | Called on object | Yes |
| Class method | static | Called on class | No, unless passed an object |
Scope determines where a variable name can be used. Local variables and parameters exist only inside the block where they are declared. When a local variable or parameter shares a name with an instance variable, the local name takes priority inside that block. The this keyword resolves the conflict by explicitly referring to the current object's instance variable.
In a constructor with a parameter named title that shadows an instance variable also named title, what does this.title = title accomplish?
| Variable type | Declared where | Scope | Access modifiers allowed? |
|---|---|---|---|
| Instance variable | Class body, outside methods | Entire class | Yes (public/private) |
| Local variable | Inside a method or block | That block only | No |
| Parameter | Method or constructor header | That method or constructor only | No |
| Term | Definition |
|---|---|
| attribute | Data stored in a class as an instance variable, representing a property unique to each object. |
| behavior | What an object can do, defined by the methods of its class. |
| constructor header | The declaration line of a constructor specifying its access modifier, the class name as the constructor name, and the parameter list. No return type is included. |
| object reference | A value that holds the memory address of an object, allowing a variable to access that object's state and methods. |
| instance method | A method that belongs to an object and is called on a specific instance using the dot operator. It can access instance variables and the this keyword. |
| side effect | An action a method performs beyond returning a value, such as modifying an instance variable or printing output. Mutator methods intentionally produce side effects. |
| variable shadowing | When a local variable or parameter shares a name with an instance variable, the local name is used inside that block, hiding the instance variable. Use this.fieldName to access the instance variable. |
| open source | Software code published and freely available for use, modification, and distribution without requiring permission or payment from the original author. |
| intellectual property | Legal rights protecting original software code. Reusing code that is not open source requires obtaining permission and often a license. |
| object composition | A design pattern where a class stores references to objects of other classes as instance variables, representing a has-a relationship. |
| dot operator | The operator (.) used to access methods and variables of a class or object, placed between the class name or object reference and the member name. |
| early return | A return statement inside a conditional or loop that exits the method before all remaining code executes. Any code after the return in the same block is unreachable. |
| caching | Storing a computed value in an instance variable to avoid recalculation. Can produce incorrect results if the underlying data changes and the cached value is not updated. |
A constructor has no return type, not even void. Writing public void ClassName() is a method, not a constructor, and the object's instance variables will never be initialized by it.
Changing a primitive parameter inside a method does not affect the original argument. Students often expect the caller's variable to update, but it never does for int, double, or boolean.
A static method has no object context. Calling an instance variable or instance method directly inside a static method causes a compile error. You must pass an object as a parameter first.
In a constructor like public Movie(String title), writing title = title assigns the parameter to itself. The instance variable never gets set. Use this.title = title to fix it.
An accessor that returns this.myList hands outside code a reference to the actual private list. The caller can then modify it, breaking encapsulation. Return a copy instead.
AP CSA free-response questions frequently ask you to write or complete a class. You may need to declare private instance variables, write a constructor that initializes them, and write accessor or mutator methods. Errors in constructor syntax (such as adding a return type) or failing to use this when a parameter shadows an instance variable are penalized.
Multiple-choice questions often present a method that receives a primitive or an object reference and ask what value a variable holds after the call. The key skill is knowing that primitives are copied (original unchanged) while object references share the same object (original can change through the reference).
Questions test whether you can identify compile errors or incorrect output caused by calling instance methods from a static context, accessing a static variable through an object reference instead of the class name, or modifying a final variable. Know the rules for what static methods can and cannot access.

Unit 3 printables
Print the unit cheatsheets ($3) or unit exams ($5) for Unit 3. Yours to keep, no subscription needed.
get printablesThe AP CSA Unit 3 progress check includes both MCQ and FRQ parts drawn from the unit's 9 topics. The MCQ portion tests your understanding of constructors, scope and access, class variables, and the `this` keyword. The FRQ portion asks you to write or analyze class definitions, including writing methods and constructors. Head to AP CSA Unit 3 for practice questions that mirror what the progress check covers.
AP CSA Unit 3 FRQs typically ask you to write a complete class or add methods and constructors to an existing one. The most tested topics are Constructors, Methods: How to Write Them, Methods: Passing and Returning References of an Object, and Scope and Access. To practice, write out full class definitions by hand, check that your constructors initialize all instance variables, and verify your method signatures match the return type. You can find Unit 3 FRQ-style practice at AP CSA Unit 3.
Start AP CSA Unit 3 by making sure you can write a class from scratch: define instance variables, write a constructor that initializes them, and add methods that return or modify those variables. Then work through Scope and Access so you know when to use `private` vs. `public`, and study Class Variables and Methods to understand the difference between instance-level and static members. Practice the `this` keyword in constructors where parameter names shadow instance variable names. After each topic, write a short Java class that uses what you just learned, then check it compiles and runs correctly. AP CSA Unit 3 has practice problems organized by topic to help you spot gaps.