It will only class level variable or data can be shared .We can create single object for each thread but we have some condition where we have to share the same object with all threads. So that synchronization is necessary between threads.
public class SynchronizationEx
private int x;
private int y;
synchronized int(int a,int b)
In java every object is having a one implicit lock on it i.e. called lock monitor.
If any thread want to run any method then it have to get that lock and only one thread can enter in synchronized method.
Synchronization degrade the performance of thread.