← Back to Week 2 Hub

Classes & Objects: Blueprint vs Instance

A class defines the structure. An object is a real thing built from that structure using the new keyword.

The Blueprint (Class Definition)
Class = Blueprint
public class Pet
Fields (what data each Pet holds)
private String name
private String species
private int age
Constructor (how to build a Pet)
public Pet(String name, String species, int age) {
  this.name = name;
  this.species = species;
  this.age = age;
}
Methods (what a Pet can do)
String getName()
void setName(String name)
String getSpecies()
void setSpecies(String species)
int getAge()
void setAge(int age)
new creates a fresh object in memory from this blueprint
Tip: The class itself doesn't hold data. It only describes what data an object will have. Each object gets its own separate copy.
Create Objects (Instances)
No objects created yet. Use the form above to create a Pet.
Modify Selected Object

Use a setter to change one value. Notice: only this object changes. Others stay the same.

Key Concepts
📜
Class = Structure
A class defines what data and methods an object will have. It's a template, not a real thing.
📦
Object = Instance
An object is a specific instance created from a class. It holds actual values in its fields.
🔗
Many from One
You can create many objects from one class. Each is independent with its own data.
🔒
Each Object is Separate
Changing one object's field with a setter does not affect any other object. They each have their own memory.
Blueprint
📐
House
🏠
Cookie Cutter
Cookies
🍪
Class
Pet
Objects
pet1, pet2...

Click on an object card to select it, then modify it with a setter. Watch how only that object changes.