can anyone explain me why there is a deadlock in this code.Thanks
public class Deadlock {
static class Friend {
private final String name;
Here's how it probably will be executed.
alphonse.bow(gaston);, alphonse is now locked due to synchronized keywordgaston.bow(alphonse);, gaston is now lockedbower.bowBack(this); from first bow method call because gaston (bower) is locked. Wait for lock to be released.bower.bowBack(this); from second bow method call because alphonse (bower) is locked. Wait for lock to be released.Both threads wait for each other to release lock.