Java OOP: Classes, Objects
Object-Oriented Programming (OOP) can feel abstract, but at its core, it mirrors the real world. Let’s break down three foundational pillars of Java OOP using structured definitions and real-world examples.
1. Defining a Class: The Blueprint
Think of a Class as an architectural drawing or a prototype. You cannot live inside a blueprint of a house; instead, the blueprint dictates the structure, characteristics, and actions common to all houses built from it.
- What it is: A user-defined template or prototype that represents a set of properties (variables) or methods common to all objects of that type.
- In Java, it looks like this:
class Vehicle {
// Instance variables (Properties)
String brand;
int speed;// Methods (Behaviors)
void accelerate() {
speed += 10;
}
}2. Instantiating an Object: The Reality
An Object is the real-world entity built directly from your blueprint. If Vehicle is the class, then your physical car parked outside is the object!
Get Priyanka Hajare’s stories in your inbox
Join Medium for free to get updates from this writer.
Creating an object from a class involves three critical steps:
- Declaration: Associating a variable name with an object type.
- Instantiation: Using the
newkeyword to allocate memory and create the physical object space. - Initialization: Following the
newkeyword with a call to a constructor to initialize its initial state.
// Combining Declaration, Instantiation, and Initialization
Vehicle myCar = new Vehicle();








