A class is a blueprint for creating objects. It defines the state (fields) and behavior (methods) of objects.

class Car {
    String color;
    int speed;
    
    void drive() {
        System.out.println("Driving...");
    }
}
 
Car myCar = new Car();
myCar.color = "Red";
myCar.drive(); // "Driving..."

Class Components

ComponentExample
FieldsString name;
Methodsvoid speak() { ... }
ConstructorCar() { ... }
BlocksStatic / instance initializer blocks
Nested ClassesInner or static nested classes

Comparison

Class vs Object

TermMeaning
ClassBlueprint / definition
ObjectInstance of a class (real-world item)

Types of Classes in Java

TypeExample Use Case
RegularStandard usage
Abstract ClassPartial implementation
FinalCannot be extended
Anonymous ClassOne-time use, inline declaration
Inner/NestedGrouped logic within outer class

Tip

Be able to explain the structure of a class, how to instantiate objects and the difference between class vs object.
Also expect questions on constructors, access modifiers or OOP principles via classes.


Parent: _OOP