2.1 Objects: Instances of Classes
Objects are the working pieces of object-oriented programming. A class describes what a type of object can store and do; an object is one actual instance made from that class. This guide explains classes, objects, instances, constructors, references, state, behavior, aliases, null values, and Java object creation with AP Computer Science A style examples.
What this lesson covers
This page is a focused study guide for objects as instances of classes, the opening idea in AP Computer Science A Unit 2. It is written for students who are beginning object-oriented programming in Java and need to understand the difference between a class blueprint, an actual object, and the reference variable that points to that object. If you are new to Java as a whole, first review why programming and why Java. If you want the wider Unit 2 path, the Using Objects category links the surrounding lessons.
The core idea: objects are instances of classes
In Java, a class is a blueprint and an object is a real item created from that blueprint. The class says what information an object can store and what actions it can perform. The object is one concrete instance with its own data. Many objects can be created from the same class, just as many houses can be built from one architectural plan or many student records can be created from one student template.
The phrase "object: instance of a class" means that an object is a specific example of a general type. If String is a class, then "RevisionTown" is a particular String object. If Scanner is a class, then a scanner object can read input from a source. If a program defines a Student class, then new Student("Aisha", 11) might create one student object with the name Aisha and grade 11.
Identity means the object is a distinct thing in memory. State means the information stored by that object, such as a name, score, balance, color, or position. Behavior means the actions the object can perform through methods, such as printing a message, calculating a value, updating a field, or returning information.
For AP Computer Science A, this idea matters because Java is designed around classes and objects. Even when you work with library classes such as String, Integer, Double, Scanner, and Math, you are using the object-oriented model. Some types create objects, some types store primitive values, and some classes provide static methods. This lesson focuses on objects as instances first, before moving into method calls, parameters, return values, string behavior, wrapper classes, and the Math class.
Class
A class is a type definition. It describes the data and behaviors available to objects of that type. Think of it as a blueprint, recipe, or template.
Object
An object is a specific instance created from a class. It has identity, can store state, and can use behaviors defined by its class.
Reference variable
A reference variable stores a reference to an object, not the object itself. It gives your code a way to access the object.
Java syntax for creating an object
In Java, an object is usually created with the keyword new. The general pattern is:
This line has three important parts. ClassName is the type of object being created. variableName is the reference variable used to access the object. new ClassName(arguments) calls a constructor, which builds and initializes the new object.
Scanner input = new Scanner(System.in);
String message = new String("Hello");
Student s1 = new Student("Maya", 11);The first line creates a Scanner object that can read from standard input. The second line creates a String object containing the characters Hello, although string literals are commonly used instead. The third line creates a Student object if a suitable Student class and constructor exist.
AP CSA students should read object creation lines from right to left. The right side creates the object. The left side declares a variable that can refer to an object of that class. After the assignment, the variable stores a reference to the object. The object itself lives separately in memory.
The next Unit 2 lesson, creating and storing objects with instantiation, develops this syntax in more detail. This page prepares the concept: a class is not the same thing as an object, and a reference variable is not the same thing as the object it refers to.
| Code part | Example | Meaning |
|---|---|---|
| Class type | Student | The object type. It tells Java what kind of object the variable can reference. |
| Reference variable | s1 | The name used in code to access the object. |
| Keyword | new | Creates a new object in memory. |
| Constructor call | Student("Maya", 11) | Initializes the new object using constructor arguments. |
| Assignment | = | Stores the reference to the new object in the variable. |
State, behavior, and identity
Objects are useful because they group related data and operations. A student object may store a name, grade level, and average score. It may also provide methods such as getName(), updateScore(), or isPassing(). The stored data is the object's state. The methods are the object's behavior. The object itself has identity because it is a distinct instance in memory.
Consider a simple class idea:
public class Student {
private String name;
private int gradeLevel;
public Student(String studentName, int level) {
name = studentName;
gradeLevel = level;
}
public String getName() {
return name;
}
}The class above describes what a Student object can store and do. Each student object has its own name and gradeLevel. When code calls getName(), the method returns the name stored in that specific object.
Student a = new Student("Maya", 11);
Student b = new Student("Noah", 12);
System.out.println(a.getName()); // Maya
System.out.println(b.getName()); // NoahBoth a and b refer to Student objects. They were made from the same class, but they are separate instances with separate state. The method call a.getName() uses the state inside the object referenced by a. The method call b.getName() uses the state inside the object referenced by b.
This is the central value of object-oriented programming. Instead of keeping many unrelated variables scattered through a program, an object collects the data and behaviors that belong together. For students learning Java, this helps explain why real programs are organized around objects rather than only around primitive variables and standalone statements.
Reference variables vs primitive variables
Java has primitive types and reference types. Primitive variables store actual simple values such as int, double, boolean, and char. Reference variables store references to objects. This difference is one of the most important concepts in AP Computer Science A because it affects assignment, comparison, method calls, and memory behavior.
| Feature | Primitive variable | Reference variable |
|---|---|---|
| Stores | The actual value | A reference to an object |
| Examples | int count = 5;boolean done = false; | String name = "Maya";Student s = new Student("Maya", 11); |
| Assignment copies | The value | The reference |
Can be null? | No | Yes |
| Method access | Primitive values do not use instance methods in the same way. | Objects are accessed through methods using dot notation. |
When you assign one primitive variable to another, Java copies the value. Later changes to one variable do not affect the other.
int a = 5;
int b = a;
b = 9;
System.out.println(a); // 5
System.out.println(b); // 9When you assign one reference variable to another, Java copies the reference. Both variables can then refer to the same object.
Student first = new Student("Maya", 11);
Student second = first;After this assignment, first and second refer to the same Student object. There are two reference variables but only one object. This is called aliasing. Aliasing is powerful but can surprise beginners because changing the object through one reference may be visible through the other reference.
If you need to review primitive types before comparing them with reference types, use the AP Computer Science A Primitive Types category. Object references become easier once the contrast with primitive storage is clear.
Constructors and object initialization
A constructor is a special block of code that runs when a new object is created. Its job is to initialize the object so it begins in a valid state. Constructors have the same name as the class and do not have a return type. They are called with the new keyword.
public class Book {
private String title;
private int pages;
public Book(String bookTitle, int pageCount) {
title = bookTitle;
pages = pageCount;
}
}The constructor Book(String bookTitle, int pageCount) receives two arguments. When a program writes new Book("Dune", 412), Java creates a new Book object and runs the constructor so that title becomes "Dune" and pages becomes 412.
Book novel = new Book("Dune", 412);The variable novel is a reference variable. It does not contain the book object directly. It contains a reference that allows the program to access that object. The object has its own state: its title and page count.
Constructors may be overloaded. That means a class can have multiple constructors with different parameter lists. For example, a Book class might have one constructor that takes both title and pages, and another constructor that supplies a default page count. Overloaded constructors make object creation flexible while still ensuring each object is initialized properly.
public Book(String bookTitle) {
title = bookTitle;
pages = 0;
}For AP CSA Unit 2, you usually use constructors from existing Java library classes before writing many of your own. Still, understanding constructors conceptually is necessary. A constructor is not a regular method call after the object exists; it is the initialization step that helps create the object.
Dot notation: accessing behavior through an object
After an object is created, Java uses dot notation to call methods on that object. The object reference appears before the dot, and the method name appears after the dot.
String word = "computer";
int length = word.length();
String upper = word.toUpperCase();In this example, word refers to a String object. The method call word.length() returns the number of characters in the string. The method call word.toUpperCase() returns a new string with uppercase letters. These are non-void method calls because they return values.
Dot notation tells Java which object should perform the method. If you have two different string objects, each method call uses the object before the dot.
String first = "Java";
String second = "Python";
System.out.println(first.length()); // 4
System.out.println(second.length()); // 6AP CSA Unit 2 builds method calling step by step. After this object-instance lesson, the sequence continues through calling a void method, calling a void method with parameters, and calling a non-void method. Those lessons depend on the idea that a method call often belongs to a specific object.
Null references and aliases
A reference variable can store null, which means it does not currently refer to any object. This is different from an object with empty or zero state. null means no object is available through that reference.
String name = null;If a program tries to call a method using a null reference, Java throws a NullPointerException.
String name = null;
System.out.println(name.length()); // Runtime errorThis happens because there is no actual String object for length() to act on. A null reference has no state and no behavior. It is only a placeholder that says the variable is not pointing to an object.
Aliasing happens when two or more reference variables refer to the same object. Consider the following example:
Student a = new Student("Maya", 11);
Student b = a;There is one object but two references to it. If the class has a method that changes the student's name, then changing the object through b would also be visible through a because both variables refer to the same object.
b.setName("Maya Chen");
System.out.println(a.getName()); // Maya ChenAliasing is not always bad. It can be useful when two parts of a program need to work with the same object. But students must understand that assignment of reference variables does not create a new object. The new keyword creates a new object. Assignment copies a reference.
new, not by counting reference variables.Object creation sentence builder
Use this quick tool to practice reading Java object creation statements. Choose a class, a variable name, and constructor arguments, then generate the statement and explanation.
AP CSA patterns involving objects
AP Computer Science A often tests object concepts through short code segments. The questions may ask what is printed, how many objects are created, whether a method call is valid, whether two references point to the same object, or why a null reference causes an error. The concepts are simple individually, but they become challenging when several appear in one snippet.
Pattern 1: Counting objects
Student a = new Student("Maya", 11);
Student b = new Student("Noah", 12);
Student c = a;This code has three reference variables but only two Student objects. The constructor is called twice with new Student(...). The assignment Student c = a; copies the reference stored in a; it does not create a new object.
Pattern 2: Predicting method results
String word = "algorithm";
System.out.println(word.length());
System.out.println(word.substring(0, 4));The variable word refers to a String object. The method length() returns 9. The method substring(0, 4) returns the characters at indexes 0, 1, 2, and 3, so it prints algo. This connects object references to method behavior and will be developed further in String objects, concatenation, literals, and more and String methods.
Pattern 3: Distinguishing object methods from static methods
double root = Math.sqrt(25);
String text = "exam";
int n = text.length();Math.sqrt(25) is called using the class name Math because it is a static method. text.length() is called using an object reference because it is an instance method on a String object. This distinction becomes important in using the Math class.
Pattern 4: Wrapper classes
Wrapper classes such as Integer and Double allow primitive values to be represented as objects. AP CSA uses wrapper classes in contexts such as array lists and object references. This connects directly to wrapper classes Integer and Double.
Objects in memory: a careful mental model
Beginners often picture a variable as a box containing a value. That model works well for primitive variables, but it is incomplete for objects. A reference variable is more like a remote control, address label, or pointer-like handle. It lets code reach an object, but it is not the object itself.
Consider this code:
Book a = new Book("Java Basics", 240);
Book b = new Book("Java Basics", 240);The two books may store identical state, but they are separate objects because new Book(...) is called twice. If the Book class does not override equality behavior, comparing the references with == checks whether they refer to the same object, not whether their contents match.
System.out.println(a == b); // false, because they are different objectsNow compare this:
Book a = new Book("Java Basics", 240);
Book b = a;
System.out.println(a == b); // true, because both refer to the same objectUnderstanding this distinction prevents many errors. If two variables refer to the same object, changes through one reference affect the same object seen through the other reference. If two variables refer to separate objects with the same state, changes to one object do not affect the other.
This is a helpful AP CSA counting rule. It is not a complete memory-management theory, but it is reliable for introductory code-tracing questions.
Code walkthrough: tracing objects and references
Trace the following code carefully. The goal is not only to know what prints, but to understand which variables refer to which objects.
Student s1 = new Student("Leah", 10);
Student s2 = new Student("Omar", 10);
Student s3 = s1;
s3.setName("Leah Kim");
System.out.println(s1.getName());
System.out.println(s2.getName());
System.out.println(s3.getName());The first line creates a Student object with name Leah. The second line creates a different Student object with name Omar. The third line copies the reference stored in s1 into s3. No third object is created. Now s1 and s3 are aliases for the same object.
When the code calls s3.setName("Leah Kim"), it changes the object that both s1 and s3 reference. Therefore, s1.getName() and s3.getName() both return Leah Kim. The object referenced by s2 is separate, so s2.getName() still returns Omar.
Leah Kim
Omar
Leah KimThis example demonstrates why a reference-variable assignment is not the same as object copying. Java does not automatically clone an object when a reference is assigned to another reference variable. It copies the reference. That single idea is tested repeatedly in object-oriented code tracing.
Strings as objects
String is one of the first object types most Java students use. A string stores a sequence of characters and provides methods such as length(), substring(), indexOf(), equals(), and compareTo(). Although Java gives string literals special syntax, strings are still objects.
String school = "RevisionTown";
int count = school.length();
String part = school.substring(0, 8);The expression school.length() calls a method on the string object referenced by school. The expression school.substring(0, 8) returns a new string containing part of the original. Strings are immutable, which means a string object cannot be changed after it is created. Methods that appear to modify a string actually return a new string.
String word = "code";
String upper = word.toUpperCase();
System.out.println(word); // code
System.out.println(upper); // CODEThe original object represented by word is not changed. The variable upper refers to a different string result. This behavior is important because it prevents mistakes such as assuming word.toUpperCase(); changes word automatically.
String behavior is central to Unit 2 because it gives students many examples of object methods. After understanding objects as instances, continue with the string lessons linked above so that method calls, return values, and immutable object behavior become natural.
Encapsulation and why object state is protected
Object-oriented programming often protects object state using private fields and public methods. This idea is called encapsulation. Encapsulation means that an object's internal data is not directly exposed to all outside code. Instead, code interacts with the object through methods. This keeps the object's state consistent and allows the class to control how changes happen.
public class BankAccount {
private double balance;
public BankAccount(double startingBalance) {
balance = startingBalance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
public double getBalance() {
return balance;
}
}In this class, balance is private. Outside code cannot directly write account.balance = -1000;. Instead, it must use methods such as deposit(). The class can validate the amount before changing state. This is one reason objects are more powerful than loose variables: the class can bundle data with rules for using that data safely.
AP CSA Unit 2 usually emphasizes using existing classes before writing full custom classes, but encapsulation is still useful to understand. When you call methods on objects, you are using the interface the class provides. You do not need to know every internal detail of how the object stores data. This is abstraction: focusing on what an object does rather than every implementation detail.
Later, when you study class design and inheritance, these ideas become even more important. Objects are not just data containers; they are structured units that support abstraction, reuse, and maintainable programs.
Object-oriented thinking in real programs
Objects help programmers model systems. A game might use objects for players, enemies, levels, scores, and items. A school system might use objects for students, courses, teachers, assignments, and grades. A shopping app might use objects for products, carts, customers, payments, and orders. Each object groups the data and actions that belong to one concept.
For example, a Product object might store a name, price, stock count, and category. It might have methods to apply a discount, update inventory, or display product information. A ShoppingCart object might store a collection of products and provide methods to add items, remove items, calculate totals, and clear the cart. The object-oriented design mirrors the real-world problem.
Good object design avoids putting everything in one huge class. Each class should represent a coherent concept. Each object should have a clear role. This makes programs easier to test, extend, and debug. If the price calculation is wrong, you know to inspect the class responsible for pricing. If student grades are wrong, you inspect the class that stores or calculates grades.
At the introductory level, the most important step is recognizing that objects make programs modular. A class defines a reusable type. An object is one instance of that type. A method call asks an object or class to perform an action. A reference variable gives your code access to an object. These ideas appear in small code snippets now and become the foundation of larger software later.
For broader computer science revision beyond AP CSA, see A Level Computer Science notes and worksheets, Computer Science 9608, and the Cambridge IGCSE Computer Science pages for 0478 and 0984.
Reading object diagrams and reference diagrams
Many teachers use diagrams to explain objects and references. These diagrams are not Java syntax, but they are useful for reasoning about code. A common diagram shows reference variables on one side and objects on another side. Arrows point from reference variables to the objects they refer to. If two arrows point to the same object, the variables are aliases. If a variable points to nothing, it stores null.
For example, after this code runs:
Book x = new Book("Algorithms", 300);
Book y = x;
Book z = new Book("Algorithms", 300);A diagram would show x and y pointing to the same object. It would show z pointing to a different object. The two book objects may have the same title and page count, but they are not the same instance. This distinction is the difference between equal state and identical object identity.
When tracing diagrams, use a slow and consistent method. First, create a new object every time you see a constructor call with new. Second, draw or imagine the reference variable pointing to that object. Third, when you see an assignment between reference variables, copy the arrow, not the object. Fourth, when a mutator method changes state, update the object at the end of the arrow.
This approach is especially useful for code with several assignments. Consider:
Student a = new Student("A", 9);
Student b = new Student("B", 10);
Student c = a;
a = b;At first, a points to the first object and b points to the second object. Then c = a; makes c point to the first object too. Finally, a = b; makes a point to the second object. At the end, a and b refer to the second object, while c still refers to the first object. The first object was not deleted by the assignment; it simply lost one reference and still has c pointing to it.
Reference diagrams also help explain why null errors happen. If a variable stores null, it has no arrow to an object. A method call requires an object at the end of the reference. Without an object, Java cannot find state or behavior, so a runtime error occurs. This visual model makes NullPointerException less mysterious.
Public interface: what an object lets other code do
A class usually exposes a public interface. The public interface is the set of constructors and public methods that outside code can use. It tells programmers how to create objects and what messages those objects understand. In AP CSA, many questions give a class description or method header, then ask what code is valid. To answer those questions, focus on the public interface.
Suppose a problem states that the Score class has the following constructor and methods:
public Score(String playerName, int points)
public String getName()
public int getPoints()
public void addPoints(int amount)From these headers, you can infer several valid statements:
Score s = new Score("Ava", 15);
String name = s.getName();
int total = s.getPoints();
s.addPoints(10);You can also identify invalid statements. If there is no zero-argument constructor, then new Score() is not valid. If addPoints is void, then int result = s.addPoints(10); is not valid because a void method does not return a value. If getName() returns a String, it cannot be stored directly in an int variable.
The public interface lets you use an object without knowing all of its private details. You may not know exactly how the Score class stores points internally, but you know that getPoints() returns an integer and addPoints(int amount) changes the object's state. This is abstraction: using the behavior promised by the class without depending on hidden implementation details.
AP questions often include class documentation in a table. Read the return type, method name, and parameter list carefully. The return type tells you whether the call produces a value. The parameter list tells you what arguments are required. The method description tells you the effect. This is a practical skill for both multiple-choice and free-response questions.
Boolean methods are also common in object interfaces. A method such as isComplete() or hasWon() returns true or false. These values connect object behavior to decision making. If you need a broader logic background, Boolean algebra is a useful related topic, although AP CSA object questions usually use Java boolean expressions rather than formal Boolean algebra notation.
Equality: same reference, same state, or same meaning?
Equality is one of the most important object topics because Java has several ideas that sound similar. Two reference variables can refer to the exact same object. Two separate objects can store the same state. Two objects can be considered equal by a class-specific equals method. These are not always the same thing.
The operator == compares primitive values directly. For reference variables, == checks whether the references point to the same object. It does not automatically compare every field inside the object.
String a = new String("cat");
String b = new String("cat");
System.out.println(a == b); // false
System.out.println(a.equals(b)); // trueThe two variables refer to different string objects, so a == b is false. But the character sequences are the same, so a.equals(b) is true. AP CSA strongly emphasizes using equals() for string content comparison. This is not just a style preference; it is a difference in meaning.
For custom classes, the behavior of equals() depends on how the class is written. If a class does not override equals(), the inherited behavior may act like reference comparison. If the class does override equals(), it may compare meaningful fields. Early AP CSA questions usually focus more on strings and references than on writing custom equals() methods, but the conceptual distinction is still useful.
Consider two student objects with the same name and grade:
Student s1 = new Student("Kai", 11);
Student s2 = new Student("Kai", 11);These are two separate instances because new Student(...) appears twice. They may represent the same real-world person if their state matches, but Java does not know that automatically. A class must define what equality means if content-based comparison is required. This is a good example of why object-oriented programming requires careful class design.
When solving AP code-tracing questions, ask exactly what is being compared. Are you comparing two primitive values? Two references? Two string contents? A method return value? A boolean expression? Slowing down at comparisons prevents many wrong answers.
From problem statement to objects
Object-oriented thinking often begins with a written problem statement. A programmer identifies important nouns, data, and actions, then designs classes and objects around them. For example, imagine a program for a library. The nouns include books, members, loans, due dates, and librarians. A Book class might store a title and author. A Member class might store a name and membership number. A Loan class might connect a book, a member, and a due date.
Not every noun must become a class, but nouns are good candidates. Actions often become methods. A library member can borrow a book, return a book, or check due dates. A book can be marked as available or unavailable. A loan can be renewed or closed. Each method belongs where it fits the responsibility of the object.
At the Unit 2 level, you are usually not expected to design a full system, but this thinking makes object examples easier. When you see a class such as Student, ask what state a student should store and what behavior a student should provide. When you see a class such as BankAccount, ask what information must be protected and what methods should control changes.
A useful design equation is:
For example, a BankAccount object remembers a balance, supports deposits and withdrawals, and protects against invalid transactions. A QuizQuestion object remembers the prompt and correct answer, supports checking a student's response, and protects the correct answer from accidental modification. These are object-oriented design decisions, not just syntax details.
This section also explains why class names are usually nouns and method names are usually verbs or verb phrases. Student, Book, and Account name things. getName(), deposit(), setScore(), and isPassing() name actions or questions. Good naming makes object-oriented code easier to read.
AP-style free-response mindset
Even though Unit 2 starts with using objects, the same ideas later appear in free-response questions. Free-response code often gives you a class with fields and methods, then asks you to complete constructors, write methods, or trace object behavior. Students who understand objects as instances of classes can reason through these questions more confidently.
When a free-response problem gives a class, first identify the instance variables. These are the pieces of state each object stores. Then identify the constructors. These explain how objects begin their lives. Next, identify accessor methods, which return information, and mutator methods, which change state. Finally, read any preconditions and postconditions because they tell you what you may assume and what your code must guarantee.
For example, a class might include:
private int score;
private String name;
public Player(String playerName) {
name = playerName;
score = 0;
}From this, you know that every Player object stores its own score and name. The constructor sets the name from the argument and starts the score at 0. If two player objects are created, each has its own separate score. Updating one player's score does not automatically update another player's score.
Many free-response mistakes happen when students forget that instance variables belong to individual objects. If a method changes score, it changes the score for the object on which the method was called. It does not change every Player object. The object before the dot matters.
Another common free-response issue is returning versus printing. A method that returns a value should use return. A method that prints output uses System.out.println. These are not the same. Object methods often return state so another part of the program can use it. Printing is only for displaying text to the console.
Common mistakes with objects and instances
Mistake 1: Calling a class an object
A class is a blueprint. An object is an instance created from the blueprint. Student is a class; new Student("Maya", 11) creates a student object.
Mistake 2: Thinking a reference variable stores the whole object
A reference variable stores a reference to an object. The object itself is separate. This is why assigning one reference variable to another can create aliases.
Mistake 3: Counting variables instead of objects
Three reference variables do not necessarily mean three objects. Count constructor calls with new to determine how many objects are created in simple AP CSA code snippets.
Mistake 4: Calling methods on null
If a reference is null, it does not point to an object. Calling an instance method on it causes a NullPointerException.
Mistake 5: Confusing == and content comparison
For reference variables, == checks whether two references point to the same object. For strings, use equals() when comparing text content.
Mistake 6: Forgetting that strings are immutable
String methods often return new strings. They do not change the original string object. Store the returned value if you want to use it later.
Mini quiz: object or class?
Question: In the statement Student s = new Student("Ava", 10);, which part creates the object?
Practice questions
- Explain the difference between a class and an object in Java.
- In the statement
Book b = new Book("1984", 328);, identify the class name, reference variable, constructor call, and object creation expression. - How many objects are created by this code?
Student a = new Student("Lina", 10); Student b = a; Student c = new Student("Lina", 10); - What is a reference variable, and how is it different from a primitive variable?
- What happens if you call an instance method on a variable whose value is
null? - Explain why
String word = "code"; word.toUpperCase();does not changeword. - Why is
Math.sqrt(25)called with a class name whiletext.length()is called with an object reference? - What is aliasing? Give a short Java example.
- Why do classes often make fields private and provide public methods?
- Write a Java statement that creates a
Scannerobject namedinputfor standard input.
Answer checks
- A class is a blueprint or type definition; an object is one instance created from that class.
Bookis the class name,bis the reference variable,Book("1984", 328)is the constructor call, andnew Book("1984", 328)creates the object.- Two objects are created because
new Student(...)appears twice.b = acopies a reference. - A primitive variable stores a simple value; a reference variable stores a reference to an object.
- Java throws a
NullPointerException. Stringobjects are immutable;toUpperCase()returns a new string that must be stored.Math.sqrtis static;length()is an instance method on a string object.
Questions and answers
What is an object in Java?
An object is a specific instance of a class. It can have identity, state, and behavior. State is the data stored by the object, and behavior is provided through methods.
What is a class?
A class is a blueprint or type definition that describes what objects of that type can store and do. A class is not the same as a particular object.
What does "instance of a class" mean?
It means the object was created from that class. For example, a String object is an instance of the String class.
What does the keyword new do?
The keyword new creates a new object and calls a constructor to initialize it.
What is a constructor?
A constructor is a special class member that initializes a new object. It has the same name as the class and does not have a return type.
What is a reference variable?
A reference variable stores a reference to an object. It allows code to access the object, but it is not the object itself.
Can two variables refer to the same object?
Yes. This is called aliasing. If two reference variables refer to the same object, changes made through one reference can be observed through the other.
Why are objects important in object-oriented programming?
Objects help organize programs by combining related data and behavior. They support abstraction, reuse, modularity, and clearer modeling of real-world systems.
Key takeaways
- A class is a blueprint; an object is an instance created from that class.
- Objects have identity, state, and behavior.
- Java commonly creates objects using
newand a constructor call. - A reference variable stores a reference to an object, not the object itself.
- Assignment between reference variables copies the reference and can create aliases.
nullmeans a reference variable does not point to an object.- Dot notation calls methods using an object reference or class name, depending on whether the method is an instance method or static method.
- Strings are objects, but they are immutable.
- AP CSA object questions often test constructor calls, references, aliases, null, and method calls.
After mastering objects as instances of classes, continue with creating and storing objects, then practice method calls, strings, wrapper classes, and the Math class across the rest of Unit 2.






