Lesson 7: Object-Oriented Basics: Classes & Objects
08 Jul 2026 1 min Swarnil Singhai
A class is a blueprint; an object is a concrete instance holding its own state — the foundation everything else in Java builds on.
Real-time example
An inventory system models each Product as a class with sku, price, stockCount — every warehouse item is one object.
class Product {
String sku;
double price;
int stockCount;
Product(String sku, double price, int stockCount) {
this.sku = sku; this.price = price; this.stockCount = stockCount;
}
boolean isLowStock() { return stockCount < 10; }
}
Product p = new Product("SKU-991", 29.99, 4);
System.out.println(p.isLowStock()); // true
What's happening
this disambiguates the field from the constructor parameter when they share a name — a very common real-world pattern.
Model real business nouns (Product, Order, Customer) as classes — the mapping from domain to code should feel obvious.
Advertisement