There are two types of Locks in java, one is object lock and other is class lock. For the object lock, you've to synchronized with the object name or this (this mean the object, which is invoking the synchronized method). And for the class lock, you've to synchronized as your original code.
And, there,
XYZ is the class name, which you supposed to lock. If you synchronized on objects, no other method belongs to that object can't be invoked with the different
thread. If you synchronized with the class lock, no other threads can invoked any static method on the class.