AP® Computer Science A review sheet from Aim for Five (aimforfive.com/csa/units/3)
Unit 3
10–18% of examClass Creation
In Unit 3 you stop just using classes and start writing your own. You plan a class from a written description, then write its private instance variables, its constructors and its methods, and you learn how static, scope and the this keyword work. You also think about the real-world impact of the programs people write. It sets you up for the Class Design free-response question.
Study this unit
Flashcards (34)Practice questions (52)Computer Science A must-know sheetFree-response questions on this unit
Write your own answer, then score it with the rubric or with AI.
- Question 1: Methods and Control StructuresRewards card constructor and top item7 points · about 25 minutes
- Question 2: Class DesignParking meter7 points · about 25 minutes
- Question 2: Class DesignThermostat modes7 points · about 25 minutes
- Question 2: Class DesignLibrary cards with numbers in order7 points · about 25 minutes
- Question 2: Class DesignOverlapping time slots7 points · about 25 minutes
- Question 2: Class DesignParty guest list7 points · about 25 minutes
Big ideas
- Abstraction hides details so you can focus on what a class or method does
- Encapsulation keeps instance variables private and exposes behavior through methods
- A constructor sets an object's initial state
- Object parameters pass a copy of the reference, so methods can change the original object
- Programs affect people, so programmers have legal and ethical responsibilities
Full unit reviews
Longer videos that cover the whole unit. Good for a first pass or a final review.
Topics
Abstraction means hiding details so you can focus on the main idea. Data abstraction names data (like a class's attributes) without showing how it's stored, and procedural abstraction lets you use a method knowing only what it does. Breaking a big behavior into smaller methods, and planning classes with diagrams, makes programs easier to build and reuse.
Key terms
- abstraction
- data abstraction
- procedural abstraction
- method decomposition
- instance variable
- class variable
A few quick questions on this topic, with the answers explained.
A reliable program does what it should under the stated conditions, which is why you test it with many kinds of input. Programs can help or harm society, the economy and culture, sometimes in ways nobody intended, and reusing someone else's code raises legal questions: open-source code is free to use under its license, but other code needs permission.
Key terms
- system reliability
- unintended consequences
- intellectual property
- open source
- licensing
A few quick questions on this topic, with the answers explained.
Every class you write starts with a header like public class Name, followed by a body with its instance variables, constructors and methods. Encapsulation means hiding a class's inner details: instance variables are private, so only the class itself can use them, while public methods and constructors give other classes controlled access. Each object gets its own copy of the instance variables.
Key terms
- encapsulation
privatepublic- instance variable
- class header
A few quick questions on this topic, with the answers explained.
Constructors
An object's state is the current values of its instance variables (the object has-a name, has-a score, and so on). A constructor sets that starting state, usually from its parameters, and if a parameter is a mutable object, the safe move is to store a copy, not the caller's reference. If you write no constructor, Java supplies a no-parameter default one, and the instance variables start at 0, 0.0, false or null.
Key terms
- constructor
- state
- has-a relationship
- default constructor
- default values
A few quick questions on this topic, with the answers explained.
A void method does a job and returns nothing, while a non-void method returns one value of its declared type. Accessor methods (getters) hand back a copy of an instance variable's value, and mutator methods (setters) change it. A return statement exits the method right away, and changing a primitive parameter never changes the caller's variable.
Key terms
voidmethod- return type
returnstatement- accessor method
- mutator method
A few quick questions on this topic, with the answers explained.
When you pass an object to a method, the parameter gets a copy of the reference, not a copy of the object, so the method can change the original object's state. Returning an object also returns a reference. A method can use the private data of a parameter only when that parameter's type is the method's own class.
Key terms
- object reference
- pass by value
- mutable object
- returning a reference
A few quick questions on this topic, with the answers explained.
A static (class) variable is shared by every object of the class, unlike an instance variable, where each object has its own copy. Static methods can work with static variables and call other static methods, but there's no object behind them, so they can't use instance variables or instance methods unless an object is passed in. A variable marked final can't be changed once it has a value.
Key terms
- class variable
- class method
staticfinal- shared copy
A few quick questions on this topic, with the answers explained.
A local variable, including a parameter, exists only inside the block where it's declared and can't be marked public or private. When a parameter or local variable has the same name as an instance variable, that name means the local one inside the method or constructor; this is called shadowing.
Key terms
- scope
- local variable
- block
- shadowing
A few quick questions on this topic, with the answers explained.
this Keyword
Inside a constructor or instance method, this refers to the current object, the one the method was called on. You often see this.name = name to set an instance variable when a parameter has the same name, and you can pass this as an argument. Static methods have no this.
Key terms
this- current object
- instance variable vs. parameter
A few quick questions on this topic, with the answers explained.