Lesson 1.12: Objects: Instances of Classes | AP CSA
Lesson 1.12: Objects: Instances of Classes
What you'll learn in this lesson
- 1.12.A. Explain the relationship between a class and an object — the class is the blueprint; an object is a specific instance with defined attribute values.
-
1.12.A. Describe the inheritance relationship every class has with
Object, and know the AP exclusion on designing inheritance hierarchies. - 1.12.B. Declare variables of reference types and explain what a reference variable holds.
This lesson is part of the AP CSA Course and Exam Description (effective May 2027).
AP exam weight: The class/object distinction underpins every OOP question. A reference variable holding a memory address — not the object itself — is essential for understanding NullPointerException and aliasing questions.
Key Vocabulary
| Term | Definition |
|---|---|
| class | The formal definition (blueprint) specifying the attributes and behaviors all instances of that type will have. |
| object | A specific instance of a class with its own set of attribute values, created at run time. |
| reference variable | A variable that holds the memory address of an object, not the object's data directly. |
| null | The value a reference variable holds when no object has been assigned to it. |
| aliasing | When two or more reference variables hold the same object address, pointing to the same object in memory. |
| Object class | The superclass of every Java class; provides toString() and equals() to all objects. |
| NullPointerException | Thrown at run time when an instance method is called on a null reference. |
Class vs Object: blueprint vs instance
A class is the formal definition — the blueprint specifying attributes and behaviors every instance will have. An object is a specific instance created at run time with its own attribute values.
The Core Distinction
String is a class. "hello" and "world" are two distinct String objects, each with its own character sequence. You can create as many objects as you need from one class definition.
Reference variables: holding an address
A variable of a reference type holds a memory address pointing to the object. It does not hold the object’s data directly.
The Rule
String name; // holds null -- no object yet name = "Tanner"; // now holds the address of the String object
Two reference variables can hold the same address (aliasing). Reassigning one variable does not affect the other.
AP Trap: == on reference types
== on reference types compares addresses, not content. Two separately created objects with identical data will have different addresses, so == returns false. Use .equals() to compare String content.
Every class extends Object
All Java classes are subclasses of Object (java.lang), giving every object toString() and equals(). Designing inheritance hierarchies yourself is outside AP exam scope.
Practice Questions
String message; without assigning a value. Which is true?message holds null because no object has been assigned.message holds "" by default.message holds memory address 0.Object class is NOT true?Object.toString() method inherited from Object.Object is in java.lang and requires no import.String a = "hello"; String b = a; a = "world";
What does
b hold after these three lines?"world"
"hello"
null
"hello world"
Scanner sc = null; then calls sc.nextInt(). What happens?NullPointerException at run time.Output Predictor — Objects and References
Type the exact output.
Bug Hunt — Objects and References
Each snippet has exactly one buggy line. Click it, then submit.
The Library System
A library uses a Book class with attributes title (String), pages (int), and methods getTitle() and isLong().
Part A
Book novel;. Which is true about novel?novel holds an empty Book with default attribute values.novel holds null because no object has been created yet.novel holds 0 because int fields default to 0.Part B
Part C: Structured response
Explain the difference between a class and an object using Book as your example. Include: what the class defines, what the object is, and why multiple different objects can come from one class.
Scoring Rubric (4 points)
- +1: Class is the blueprint: defines attributes (title, pages) and behaviors (getTitle, isLong) every Book will have.
- +1: Object is a specific instance: e.g., a Book with title "1984" and pages 328.
- +1: Multiple objects possible: each has its own attribute values even though all share the same class structure.
- +1: Correct terminology: class=blueprint/definition, object=instance.
Heap vs Stack memory
Primitive variables live on the call stack. Objects are allocated on the heap. Reference variables on the stack hold the heap address. When a method returns, its stack frame is discarded, but heap objects persist until garbage collection. This explains why aliasing works: two stack variables can point to the same heap object.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]