Learn Apex
Static vs instance
Instance fields and methods belong to one object you construct. Static belongs to the class — one shared value across all instances in the transaction (unless reset).
Scope

Create instances (simulated)

Instance counter

0

instanceHits per object

Static counter (fixed demo)

0

staticHits shared — every tap bumps it

Pattern
public class CounterDemo {
    public static Integer staticHits = 0;
    public Integer instanceHits = 0;

    public void tap() {
        staticHits++;
        instanceHits++;
    }
}

Triggers and tests can re-use static state — be careful with recursion and test isolation; often reset statics in test setup when needed.