A method inside a class defines behavior that every object of that class can perform:
class Car {
String color;
int speed;
void accelerate(int amount) {
speed = speed + amount;
}
}
Now every Car object has an accelerate method. When you call myCar.accelerate(10), it increases that specific car's speed by 10. The method operates on the fields of the object you called it on.
This is the core of OOP. Data (speed) and behavior (accelerate) live together in the same class, so you never accidentally modify the wrong car's speed.