What is a Class?
A class is like a blueprint or template.
It defines properties (variables) and behaviors (methods) of an object.
Example:
Think of Car as a class. It describes general features like color, model, speed and actions like drive(), brake().
What is an Object?
An object is a real-world instance of a class.
Using the Car class, you can create many Car objects (BMW, Audi, Tesla).
Each object has its own data but follows the class template.
Example in Java
// Class Definition
class Car {
// Properties (variables)
String color;
String model;
int speed;
// Method (behavior)
void drive() {
System.out.println(model + " is driving at speed " + speed + " km/h.");
}
}
So in short:
Class = Blueprint
Object = Real-world instance created from class
Top comments (0)