The Stacks
UNIT 3: CLASS CREATION · CHEAT SHEET

Class Creation — the one-page version

Every key term and every exam tip from the 9 topics in this unit. Print it, fold it, read it on the bus.

3.1Abstraction and Program Design

Data abstraction
modeling a concept as a class with attributes
Procedural abstraction
using a method without knowing its implementation
Encapsulation
keeping data private and controlling access through public methods
Tip: On FRQ 2, underline every noun that's a piece of state (becomes an instance variable) and every verb (becomes a method). The prompt tells you the class's design; your job is to translate it faithfully, not invent extras.

3.2Impact of Program Design

Data minimization
collecting and storing only the data a program actually needs
Accessibility
designing so people with disabilities and varied contexts can use the program
Tip: Questions here are scenario-based and the right answer usually involves collecting less data, validating before storing, considering users unlike the developer, or getting consent. Options that maximize data collection "just in case" are wrong.

3.3Anatomy of a Class

Instance variable
a variable declared in a class that each object has its own copy of
private
accessible only within the class
public
accessible from any class
Default value
the automatic initial value of an instance variable: 0, 0.0, false, or null
Tip: FRQ 2 rubrics award a point for declaring instance variables private. Forgetting private costs it every year. Also, a class with instance variables but no constructor is legal — Java provides a default one — but on the FRQ you'll be asked to write one.

3.4Constructors

Constructor
a method with the class's name and no return type that initializes a new object
No-argument constructor
a constructor with no parameters that sets default values
Default constructor
the no-arg constructor Java provides only when a class defines none
Tip: Two mistakes cost FRQ points every year: writing public void Rectangle(...) (the void makes it a method, not a constructor) and assigning parameters to nothing (w = width; backwards). Instance variable on the left, parameter on the right.

3.5Methods: How to Write Them

Accessor method
returns the value of an instance variable without changing it
Mutator method
changes an instance variable; typically void
toString
a method returning a String representation of the object, called automatically by println
Tip: If the prompt says "returns," write return; if it says "prints," write System.out.println. Mixing them up is a full rubric point. For toString, always return. For every non-void method, ask: does every possible path hit a return?

3.6Methods: Passing and Returning References of an Object

Pass by value
Java copies the argument's value; for objects that value is a reference
Reference parameter
a parameter that holds the address of the caller's object
Tip: Draw the arrow. Parameter and argument arrows point to the same box; mutating the box is visible to both. Reassigning the parameter moves only the parameter's arrow. Primitives are just copied numbers.

3.7Class Variables and Methods

Class variable / static variable
a single variable shared by all objects of a class
Class method / static method
a method called on the class that can't use instance variables
Constant
a static final variable whose value never changes
Tip: "Which variable should be static?" — anything that's the same for every object or tracks the class as a whole. "Why won't this compile?" — a static method touching an instance variable. Trace static variables as one shared cell, not one per object.

3.8Scope and Access

Scope
the region of code in which a variable is accessible
Local variable
a variable declared inside a method or block
Shadowing
a local variable or parameter hiding an instance variable of the same name
Tip: Find the closing brace of the block a variable was declared in — that's the end of its life. If a question uses a variable after that brace, it's a compile error. For shadowing, the closest declaration wins.

3.9this Keyword

this
a reference to the object on which the current method or constructor was invoked
Tip: When a constructor's parameters share names with instance variables, look for this. on the left side. If it's missing, the instance variables are never set — a classic "why does getTitle() return null" question.