Module 5: Classes, Objects, and Constructors
What a Class Is and What an Object Is
Learn the basic class-and-object model so Java programs can represent real things instead of only printing values.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-16
Java version
Java 25 LTS
Learning goals
- Understand the difference between a class and an object
- Recognize why objects are useful in Java
- See how classes group related data and behavior
Why this matters: Once your programs get bigger, loose variables and functions become hard to manage. Classes let you group related data and behavior together.
A class is a blueprint: It describes what kind of data an object should store and what actions it should support.
An object is a real instance of that blueprint: If Car is the class, then familyCar and schoolCar are separate objects with their own values.
Beginner mental model: A class describes the kind of thing. An object is one actual thing created from that description.
Runnable examples
A class describes a kind of thing
class Book {
String title;
int pages;
}
public class Main {
public static void main(String[] args) {
Book favorite = new Book();
favorite.title = "Java Basics";
favorite.pages = 180;
System.out.println(favorite.title);
}
}Expected output
Java Basics
Two objects can come from the same class
class Dog {
String name;
}
public class Main {
public static void main(String[] args) {
Dog first = new Dog();
Dog second = new Dog();
first.name = "Milo";
second.name = "Nora";
System.out.println(first.name);
System.out.println(second.name);
}
}Expected output
Milo Nora
Common mistakes
Thinking a class is the same thing as one object
A class is the plan. Each `new` call creates an object from that plan.
Mini exercise
Create a `Student` class with fields for `name` and `grade`, then create one `Student` object and print its values.
Summary
- A class is a blueprint.
- An object is an instance created from that blueprint.
- Classes group related data and behavior.
Next step
Now add fields and methods so your classes can both store data and do something with it.
Sources used