Let's say you have two different instances of the same class, who need to update some static field when they do work. In this case, you will have to use the class to synchronize on, because the static field is shared between instances:
In this code, n keeps track of how often doStuff is called, no matter on which instance it is called on. In order to update n, you need to make sure that no other
thread accesses it at the same time. Because n is shared between different instances, you can't use synchronized(this), you have to use a lock that is also shared between different instances. In this case, we use Example.class, which we can be quite certain will be shared between all instances of Example.
Note that it doesn't matter what lock you use to synchronize on, as long as it is the same lock for all instances. We could also have used Object.class (which is also visible to all instances of Example) or even String.class or some static Object field in Example:
Note that using the current class (Example.class in this case) is just the standard way of doing things.