1. Class
- A blueprint / template for creating objects.
- It defines fields (data) and methods (behavior).
- Does not occupy memory until you create an object.
class Car {
String color;
void drive() {
System.out.println("Driving...");
}
}2. Object
- A runtime entity created from a class.
- When you do
new Car(), Java allocates memory and creates an object. - Objects hold actual values in their fields.
Car car1 = new Car(); // object created
car1.color = "Red";Here,car1is an **object** of classCar`.
3. Instance
- “Instance” is another word for object, but emphasizes the relationship with its class.
- You can say:
car1is an object of typeCar.car1is an instance of classCar.
差不多一个意思
👉 The difference is mostly in wording:
- object → physical entity in memory.
- instance → conceptual: “this object belongs to that class”.