What is the relationship between a class and an object, and what does it mean to say an object is an instance of a class?
Topic 2.1 Objects: Instances of Classes: explain the relationship between a class and its objects, and describe an object as an instance of a class with state and behavior.
A focused answer to AP CSA Topic 2.1, covering the class-object relationship, what it means for an object to be an instance, the difference between attributes (state) and methods (behavior), and reference versus primitive variables, with a worked example.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
What this topic is asking
The College Board (Topic 2.1) wants you to explain the relationship between a class and an object: a class is a blueprint, and an object is an instance built from it. You should describe an object in terms of its state (the data in its attributes) and its behavior (what its methods do), and recognize that an object variable is a reference type, unlike the primitives of Unit 1.
Class and object
Think of the class as the design and the object as a product made from that design. The class String is a blueprint; "hello" is one String object made from it. You can build many objects from one class, and each object is independent: changing one does not change another.
State and behavior
Every object has two aspects:
- State - the data the object currently holds, stored in its attributes (also called instance variables or fields). Two objects of the same class can have different state.
- Behavior - what the object can do, defined by its methods. Calling a method may read or change the object's state.
For a Rectangle class, the state might be a width and a height; the behavior might be a method that returns the area. Each Rectangle object has its own width and height (its state), but they all share the same set of methods (their behavior) defined by the class.
Reference types
This distinction matters throughout Unit 2. When you write String s = "hi";, the variable s does not contain the characters; it contains a reference to a String object that holds them. Understanding that object variables are references explains why two variables can refer to the same object, and why a freshly declared object variable can be null until you create an object for it (Topic 2.2).
Try this
Q1. State the difference between a class and an object. [2 points]
- Cue. A class is a blueprint defining attributes and methods; an object is a specific instance created from that class, with its own attribute values.
Q2. Identify whether a String variable stores the characters directly or a reference to them, and name the category of type. [2 points]
- Cue. It stores a reference to a
Stringobject, not the characters directly;Stringis a reference type.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2021 (style)1 marksMultiple choice. Which statement best describes the relationship between a class and an object in Java?
(A) A class is a single value, and an object is a copy of it.
(B) A class is a blueprint that defines attributes and behaviors; an object is a specific instance created from that class.
(C) An object defines the attributes, and a class is one instance of the object.
(D) A class and an object are two names for the same thing.
(E) An object can exist without any class.
Show worked answer →
The answer is (B).
A class is a blueprint or template that specifies what data (attributes) an object holds and what it can do (methods); an object is a concrete instance built from that blueprint, with its own values for the attributes. (C) reverses the roles. (A), (D) and (E) misstate the relationship - objects in Java are always created from a class, and many objects can be made from one class.
Markers reward identifying the class as the template and the object as an instance of it.
AP 2019 (style)3 marksFree response (short answer). A class `BankAccount` stores a balance and can deposit and withdraw money. (a) Using the terms class, object and instance, describe the relationship if `acct1` and `acct2` are both made from `BankAccount`. (b) Explain what is meant by the state and the behavior of an object.
Show worked answer →
A 3-point short-answer question testing object-oriented vocabulary.
(a) Point 1: BankAccount is the class (the blueprint); acct1 and acct2 are two separate objects, each an instance of the BankAccount class, with their own independent balances.
(b) Point 2: the state of an object is the data it currently holds in its attributes (here, the balance). Point 3: the behavior of an object is what it can do, defined by its methods (here, deposit and withdraw), which can change the state.
Markers reward correct use of class, object and instance, and distinguishing state (data) from behavior (methods).
Related dot points
- Topic 2.2 Creating and Storing Objects (Instantiation): use the new keyword to call a constructor and instantiate an object, choosing the correct constructor by its parameters, and store the result in a reference variable.
A focused answer to AP CSA Topic 2.2, covering the new keyword, constructors and how they initialise an object, choosing a constructor by its parameter list, matching argument types, storing the reference, and the meaning of null, with a worked example.
- Topic 2.3 Calling a Void Method: call a non-static void method on an object using dot notation, and explain that a void method performs an action but returns no value.
A focused answer to AP CSA Topic 2.3, covering dot notation for calling methods on objects, what void means, why a void call cannot be used in an expression, the difference between a method signature and a call, and method side effects, with a worked example.
- Topic 2.5 Calling a Non-void Method: call a method that returns a value, and use the returned value by storing it, printing it, or including it in an expression.
A focused answer to AP CSA Topic 2.5, covering methods that return a value, the return type, using a returned value in an assignment, expression or print, the difference from a void method, and chaining method calls, with a worked trace.
- Topic 1.2 Variables and Data Types: identify the primitive types int, double and boolean, and declare, initialise and use variables of those types.
A focused answer to AP CSA Topic 1.2, covering the difference between primitive and reference types, the three exam primitives int, double and boolean, declaring and initialising variables, valid identifiers, and constants, with a traced worked example.
- Topic 2.6 String Objects: Concatenation, Literals, and More: create String objects from literals or a constructor, concatenate strings with the + operator, and predict the result of mixing strings with numbers and escape sequences.
A focused answer to AP CSA Topic 2.6, covering String literals and the String constructor, concatenation with the plus operator, the rule that any value concatenated with a String becomes a String, left-to-right evaluation traps, and escape sequences, with a worked trace.
Sources & how we know this
- AP Computer Science A Course and Exam Description — College Board (2025)