Skip to main content
← AP CSA Study Guide

Unit 7 · Heavy

Methods, Classes, and Objects

Where the free-response section lives. The unit covers writing a method to a specification and designing a class that protects its own state, which together account for most FRQ credit.

What a strong answer looks like

A strong Unit 7 answer names the parameters, the return type, and what the method must leave unchanged, before writing a single line of the body.

Topics in this unit

1

Methods and Parameters

Practice this topic →

Know

Java passes parameters by value. For a primitive the method gets a copy; for an object it gets a copy of the reference, so it can change the object but not repoint the caller variable.

Apply

Decide for each parameter whether the method can affect the caller, and trace accordingly.

Watch out

Expecting a method to change a caller’s int, or expecting reassigning an object parameter to affect the caller.

Study move

Write one method that fails to change an int and one that succeeds in changing an array, and explain the difference.

2

Return Values

Practice this topic →

Know

A return immediately ends the method and hands back a value of the declared type. Every path through a value-returning method must return.

Apply

Check that each branch returns, including the fall-through case after a loop.

Watch out

Printing instead of returning, which produces visible output but no usable value and loses FRQ points.

Study move

Write a search method returning an index, and confirm every path including no-match returns something.

3

Classes and Constructors

Practice this topic →

Know

A constructor initialises an object’s fields and shares the class name with no return type. Multiple constructors are distinguished by their parameters.

Apply

Initialise every field in every constructor, so no object begins in a half-built state.

Watch out

Writing a return type on a constructor, which turns it into an ordinary method that is never called.

Study move

Write a class with two constructors and confirm both leave every field initialised.

4

Object State and Encapsulation

Practice this topic →

Know

Encapsulation keeps fields private and exposes behavior through methods, so an object controls how its own state changes.

Apply

Make fields private and provide only the accessors and mutators the class actually needs.

Watch out

Returning a reference to a mutable field, which lets outside code change the object’s state directly.

Study move

Write a class whose getter returns a copy rather than the field itself, and explain why.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Writing the method signature exactly as specified before the body
  • Returning rather than printing
  • Keeping fields private and initialising them in every constructor

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Inheritance and polymorphism. Depth varies widely; the exam keeps to straightforward overriding.
  • Interfaces. Emphasised in some courses more than the exam requires.
  • static members. Introduced at different points depending on the course.

Mastery checklist

  • Explain what a method can and cannot change about a caller’s variable.
  • Confirm every path of a value-returning method returns.
  • Write a constructor that initialises all fields.
  • Explain why a getter might return a copy.

Check yourself

  • Why can a method change an array parameter but not an int parameter?
  • What is wrong with a constructor that declares a return type?
  • How does returning a reference to a private field break encapsulation?

Modeling drill

Write a class holding a list of scores with a method returning the highest, keeping the list private and safe from outside modification.

Pass by valueReferenceReturn typeConstructorEncapsulationAccessorMutator