AP® Computer Science A Unit 3 flashcardsClass Creation
34 cards · about 9 minutes for the whole deck
Flashcard drill
Space flips the card, arrow keys move, and keys 1 to 4 rate how well you knew it.
- Position
- 1 / 34
- Due
- 34
- Mastered
- 0 / 34
This card: New
Flip the card before you rate it.
Abstraction
Hiding details so you can focus on the main idea. It makes big programs easier to build and understand.
Topic 3.1: Abstraction and Program Design
Data abstraction
Naming data without showing how it's stored, like a class's attributes. You use the data without knowing its inner details.
Topic 3.1: Abstraction and Program Design
Procedural abstraction
Using a method knowing only what it does, not how. The method's inside can change as long as its header and job stay the same.
Topic 3.1: Abstraction and Program Design
Method decomposition
Breaking a big behavior into smaller methods, one for each task. It cuts down on repeated code and makes the class easier to fix.
Topic 3.1: Abstraction and Program Design
Instance variable
An attribute declared in a class, outside any method, where each object gets its own copy, like each pet's
age.Topic 3.1: Abstraction and Program Design
Class variable
A
staticattribute with one copy shared by every object of the class, like a count of objects created.Topic 3.1: Abstraction and Program Design
System reliability
A program doing what it should under the stated conditions without failing. Test with many kinds of input to improve it.
Topic 3.2: Impact of Program Design
Unintended consequences
Harmful effects a program has beyond its intended use, which its designers didn't plan for. Programs can help and harm at once.
Topic 3.2: Impact of Program Design
Intellectual property
Creative work, including code, that belongs to someone. Using code that isn't open source needs the owner's permission and often payment.
Topic 3.2: Impact of Program Design
Open source
Code published for anyone to use, study and change, under the terms of its license.
Topic 3.2: Impact of Program Design
Encapsulation
Hiding a class's data by making instance variables
private, so other classes use it only throughpublicmethods.Topic 3.3: Anatomy of a Class
privateAccess only from inside the declaring class. Instance variables and helper methods are usually
private.Topic 3.3: Anatomy of a Class
publicAccess from any class. In this course, classes and constructors are always
public, along with methods meant for other classes.Topic 3.3: Anatomy of a Class
Class header
The first line of a class, like
public class Pet. The body in braces holds the instance variables, constructors and methods.Topic 3.3: Anatomy of a Class
State
An object's attributes and their current values, stored in its instance variables. The object has-a value for each one.
Topic 3.4: Constructors
Has-a relationship
An object has-a piece of data when it's one of its instance variables, like a
Carthat stores anEngine.Topic 3.4: Constructors
Default constructor
The no-parameter constructor Java supplies when a class has none. Instance variables get default values.
Topic 3.4: Constructors
Default values
intstarts at 0,doubleat 0.0,booleanatfalseand any reference type atnull, for instance variables that aren't set.Topic 3.4: Constructors
Copying a mutable parameter
If a constructor gets a mutable object, store a new copy, not the caller's reference, so later outside changes can't affect your object.
Topic 3.4: Constructors
voidmethodA method that does a job but returns nothing. Call it as a statement on its own; you can't store or print its result.
Topic 3.5: Methods: How to Write Them
Return type
The type of value a non-
voidmethod gives back, written before the method name. Every path through the method must return a value of that type.Topic 3.5: Methods: How to Write Them
returnstatementSends a value back and ends the method right away, even inside a loop. Any code after it on that path never runs.
Topic 3.5: Methods: How to Write Them
Accessor method
A getter, like
getAge(), that returns a copy of an instance variable's value without changing anything.Topic 3.5: Methods: How to Write Them
Mutator method
A setter, like
setAge(int a), that changes an instance variable. It's oftenvoidand can reject bad values.Topic 3.5: Methods: How to Write Them
Passing an object reference
The parameter gets a copy of the reference, not of the object. The method can change the object, but pointing the parameter elsewhere doesn't affect the caller.
Topic 3.6: Methods: Passing and Returning References of an Object
Returning a reference
A method that returns an object returns a reference to that same object, not a new copy, so changes through it affect the original.
Topic 3.6: Methods: Passing and Returning References of an Object
Private access within a class
Code inside a class can use the private data of any object of that class, like
other.centsinsideMoney. Other classes can't.Topic 3.6: Methods: Passing and Returning References of an Object
What a
staticmethod can useA
staticmethod can use static variables, but it has nothisand no instance variables of its own.Topic 3.7: Class Variables and Methods
finalMarks a variable that can't be changed once it has a value, like
final int MAX = 10;. Trying to change it won't compile.Topic 3.7: Class Variables and Methods
Local variable
A variable declared inside a method or block, including parameters. It exists only in that block and can't be
publicorprivate.Topic 3.8: Scope and Access
Scope
The part of the code where a variable can be used. A variable declared in a block can't be used after the block's closing brace.
Topic 3.8: Scope and Access
Shadowing
When a parameter or local variable has the same name as an instance variable, the name means the local one inside that method.
Topic 3.8: Scope and Access
thisInside a constructor or instance method, a reference to the current object.
this.name = namesets the instance variable from a same-named parameter.Topic 3.9: this Keyword
Passing
thisthiscan be an argument, likeclub.add(this), to hand the current object to another method. Static methods have nothis.Topic 3.9: this Keyword