0/30 Days Completed 0 Learning Days
Day 16 of 30 · Week 3 — OOPS Fundamentals
Classes and Objects
1 Learn
A class is a blueprint. An object is a real thing built from that blueprint. One class can create many objects.
Each object has its own copy of the fields, so changing one object does not change another.
2 See the Code
Java
class Book {
String title;
int pages;
void show() {
System.out.println(title + " (" + pages + " pages)");
}
}
public class Shelf {
public static void main(String[] args) {
Book a = new Book();
a.title = "Code Garden";
a.pages = 220;
Book b = new Book();
b.title = "Object Trails";
b.pages = 310;
a.show();
b.show();
}
}- Book is one class; a and b are two separate objects.
- Each object stores its own title and pages.
Output
Code Garden (220 pages) Object Trails (310 pages)
3 Practice
- Create a Car class with brand and speed, make two Car objects, and print both.
Try it in your own Java setup or write it in the Practice Notebook.
4 Quick Check
1. A class is best described as...
2. Which keyword creates an object?
Step 5
Answer and check the Quick Check above to unlock this.