ACSA Exam Prep
Unit 1 · Using Objects and Methods · Topic 1.12

Objects: Instances of Classes

Skill 4.A

Big idea: A class is a blueprint; an object is one thing built from it. A reference variable doesn't hold the object, it holds a way to find it.

Learning objectives
  • Explain the relationship between a class and an object.
  • Develop code to declare variables to store reference types.

Class vs. object

A class defines the attributes and behaviors that all its objects share. An object is a specific instance of the class with its own values. Many objects can be made from one class, and each stores its own data.

A class can extend a superclass, inheriting its attributes and behaviors. Every class is ultimately a subclass of Object. You only need to recognize this idea; writing inheritance hierarchies is not tested.

References and aliases

A reference variable holds an object reference, which you can think of as the object's memory address. Assigning one reference variable to another copies the reference, not the object, so both variables now refer to the same object. They are aliases.

Code
Counter a = new Counter();
Counter b = a;
b.increment();
b.increment();
System.out.println(a.getCount());
Counter c = new Counter();
System.out.println(c.getCount());
Output
2
0
Key points
  • A class is the blueprint; an object is a specific instance with its own attribute values.
  • A reference variable holds an object reference (like an address), or null.
  • Copying a reference makes an alias: two variables, one object.
  • Every class is a subclass of Object.
Watch out
  • Copying a reference does not copy the object. A change through one alias is visible through the other.
Quick check
If Dog c = a; and then c's name is changed, does a's name change?
Show answer
Yes. a and c refer to the same Dog object.
Not on the exam
  • Designing and implementing inheritance relationships.